Entity Framework: How to disable lazy loading for specific query?

Marco Alves picture Marco Alves · Jun 3, 2014 · Viewed 78.9k times · Source

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.

Answer

Karthik Ganesan picture Karthik Ganesan · Jun 6, 2016

set the following code before the query you want to execute

context.Configuration.LazyLoadingEnabled = false;