Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting entity framework context in Linqpad?

I've created a DLL assembly which contains the edmx for northwind database.

I created a reference to that dll through linqpad and I do see the db and able to run queries.

But - I want to test the behavior of DeferredLoadingEnabled property and I need to set it via the context variable.

eg

ctx.DeferredLoadingEnabled = false;

But how can I access ctx?

linqpad generates it for me , and I need to access it.

like image 307
Royi Namir Avatar asked Sep 24 '13 17:09

Royi Namir


2 Answers

In Entity Framework 5, the equivalent property is:

ctx.Configuration.LazyLoadingEnabled = false;

If you're in LINQPad, you're already in the context, so you can just say:

Configuration.LazyLoadingEnabled = false;

But when I'm copying code from Visual Studio to LINQPad, I'll often just add a line at the top so all the code works the same:

var ctx = this;
like image 71
StriplingWarrior Avatar answered Oct 26 '22 13:10

StriplingWarrior


There is no DeferredLoadingEnabled property in Entity Framework - it is part of Linq to SQL, not Linq to entities (EF).

Entity Framework has deferred loading by default. The linked tables will be loaded on access or when you explicitly load them yourself or when you load them directly with the first resource (eager loading).

like image 35
user2674389 Avatar answered Oct 26 '22 14:10

user2674389