Is there any way to disable lazy loading for specific query on Entity Framework 6? I want to use it regularly, but sometimes I want to disable it. I'm using virtual properties to lazy load them.
You can turn off deferred loading by setting DeferredLoadingEnabled to false .
Lazy loading can be turned off for all entities in the context by setting a flag on the Configuration property to false as shown in the following example. After turning off lazy loading, now when you run the above example again you will see that the Enrollments are not loaded and only student data is retrieved.
You can turn off the lazy loading of all entities by making LazyLoadingEnabled property to false in the constructor of the DbContext class as shown below.
set the following code before the query you want to execute
context.Configuration.LazyLoadingEnabled = false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With