Alex Rivera | Logout

Disable lazy loading by default in Entity Framework 4

Asked 2010-06-03T15:08:43.163
62

It seems that lazy loading is enabled by default in EF4. At least, in my project, I can see that the value of

dataContext.ContextOptions.LazyLoadingEnabled

is true by default. I don't want lazy loading and I don't want to have to write:

dataContext.ContextOptions.LazyLoadingEnabled = false;

each time I get a new context. So is there a way to turn it off by default, say, across the whole project?

Edit
Report

1 Answer

4

If you are modelling code-first, simply remove the virtual keyword on your reference/object properties. Having virtual on a reference will enable LazyLoading on that particular reference.

answered 2013-07-07T14:40:51.057

Your Answer