Entity Framework Core include loading extra navigational properties

.net-core .net-core-2.1 c# entity-framework-core

Question

I am using .NET Core and EF Core 2.1.

I am using a very simple type query:

var entities = context.SomeEntity
                      .Include(s => s.AnotherEntity)
                      .ToList();

This works fine, but if AnotherEntity has navigational properties, it loads those automatically. This is becoming a problem with very large applications because some of my web api calls are returning large amounts of data because the of all the nested entities.

Is this a model design problem or setting I can't find? I have not enabled lazy loading.

EDIT

Turns out the problem was there were multiple other context calls within the same webapi action. If a navigation property existed on one of the other calls, it would load all navigation properties. I fixed it by adding .AsNoTracking().

1
0
6/2/2018 1:10:48 AM

Popular Answer

You can read this documentation about lazy-loading.

Maybe you can solve your problem by using the proxies Nuget pacckage

Also, remember that navigation properties in your classes must be virtual.

0
6/1/2018 10:19:58 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow