Royi Namir
Royi Namir

Reputation: 148524

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.

Upvotes: 9

Views: 8024

Answers (3)

StriplingWarrior
StriplingWarrior

Reputation: 156524

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;

Upvotes: 13

Jens Kloster
Jens Kloster

Reputation: 11277

When using Linqpad, you are acually inside the ObjectContext. Just type:

this.

and you can access the properties on your ObejctContext.

(also: make sure you use "C# Statement")

Upvotes: 6

user2674389
user2674389

Reputation: 1143

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

Upvotes: 5

Related Questions