This is because Entity Framework is not entirely stupid. It sees that in the end only System
s are queried, so it cuts everything in between and returns System
s only. And part of the trick you're executing here is to disable lazy loading, so the navigation properties are null and will remain null.
You have to remove the last Select
out of the scope of the EF query provider by adding an AsEnumerable
:
return ctx
.Include(s => s.Customer.CustomerType)
.Select(s => new {
System = s,
VRTSystemProductConfigurations = s.VRTSystemProductConfigurations.Where(pc => pc.Active)
})
.AsEnumerable()
.Select(s => s.System);
And you don't want to include VRTSystemProductConfigurations
, because that's the collection you want to load partly.