Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 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.

like image 714
BrooklynDev Avatar asked Dec 19 '10 21:12

BrooklynDev


1 Answers

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();
like image 98
Joe Albahari Avatar answered Nov 02 '22 09:11

Joe Albahari