C# – Entity Framework: How to disable lazy loading for specific query

centity-frameworklazy-loading

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.

Best Answer

set the following code before the query you want to execute

context.Configuration.LazyLoadingEnabled = false;