Disable Lazy Loading for a specified query

1

I'm having a sloppy problem when it comes to fetching the data.

I have 16 thousand records in the table that are taking about 6 seconds to be fetched.

I noticed that while bringing these records this is also bringing the related records due to lazy loading . However, in this particular query there is no need to bring related records.

I think I might gain some time if I do not bring these unnecessary records, follow the code:

public IList<NotaMercadoria> GetAll(long pIdCadEmpresa)
{
    return entity.NotaMercadoria.Where(x => x.IDCadEmpresa == pIdCadEmpresa).ToList();
}

Since there is no need to bring related records, is there any way to disable lazy loading for this query in specifies?

    
asked by anonymous 28.09.2017 / 20:17

1 answer

3

Just disable it before fetching the data.

public IList<NotaMercadoria> GetAll(long pIdCadEmpresa)
{
    entity.Configuration.LazyLoadingEnabled = 
    entity.Configuration.ProxyCreationEnabled = false;

    return entity.NotaMercadoria.Where(x => x.IDCadEmpresa == pIdCadEmpresa).ToList();
}
    
28.09.2017 / 20:22