Select is missing .ThenInclude EF query

c# entity-framework-core sql sql-server

Question

I have a query that ended up being n^3 so I'm simplifying it. I found a way to write it to only be n^2 but for some reason the .ThenInclude property is missing. Is this not the right way to write it?

test.Include(t => t.a)
     .Include(t => t.b)
         .ThenInclude(b => b.c)
     .Where(t => Users.Exists(u => u.Id == t.a.Id))
     .Select( t => t.b)
     .ToListAsync()

This returns a list of 'b' but b.c is null when I try to access it.

1
0
3/30/2018 9:08:04 PM

Accepted Answer

From Microsoft docs:

If you change the query so that it no longer returns instances of the entity type that the query began with, then the include operators are ignored.

https://docs.microsoft.com/en-us/ef/core/querying/related-data

You need to rewrite your query to originally return "b" values.

2
3/30/2018 7:56:12 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