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

Solution 1:

set the following code before the query you want to execute

context.Configuration.LazyLoadingEnabled = false;

Solution 2:

You can disable Lazy loading for a specific query as follows :

public static Cursos GetDatosCursoById(int cursoId)
{
    using (var bd = new AcademyEntities())
    {
        try
        {
            bd.Configuration.ProxyCreationEnabled = false;
            return bd.Cursos.FirstOrDefault(c => c.cursoId == cursoId);
        }
        catch (Exception ex)
        {
            return null;
        }
    }
}