开发者

Is it possible to define a usable Object Context variable in LINQPad?

开发者 https://www.devze.com 2023-01-31 14:06 出处:网络
I\'d like to be able to write against an object context variable within linq pad so the code is identical to what I\'ll be using in my production code. For instance if my object 开发者_JAVA百科context

I'd like to be able to write against an object context variable within linq pad so the code is identical to what I'll be using in my production code. For instance if my object 开发者_JAVA百科context variable was 'oc':

oc.Products.Where(p => p.Price > 10m);

Instead of:

Products.Where(p => p.Price > 10m);

Where the object context would be available in a variable name of my choosing instead of not using a local variable for the object context which is the same LINQPad works by default.


LINQPad subclasses the object context, so you can get to it via the 'this' keyword. Assigning it to a local variable will do what you want:

var oc = this;
oc.Products.Where (p => p.price > 10).Dump();
0

精彩评论

暂无评论...
验证码 换一张
取 消