The EF Core equivalent syntax of EF6
.Include(x => x.Tests.SelectMany(z => z.PupilsTests))
is
.Include(x => x.Tests).ThenInclude(x => x.PupilsTests)
Note that there seems to be a VS Intellisense issue inside the ThenInclude
, so just type the above and it will compile successfully and work.
Also please note that EF Core processes collection includes differently (does not use single query as in EF6), so the above would generate and execute 3 SQL queries.
Update: The VS Intellisense issue now is specifically mentioned in the EF Core documentation under Including multiple levels section:
Note!
Current versions of Visual Studio offer incorrect code completion options and can cause correct expressions to be flagged with syntax errors when using the ThenInclude
method after a collection navigation property. This is a symptom of an IntelliSense bug tracked at https://github.com/dotnet/roslyn/issues/8237. It is safe to ignore these spurious syntax errors as long as the code is correct and can be compiled successfully.