Turn on the collection and then the collection one level down

I am trying to query the collection and child collection using EF 7. Here is the code:

public async Task < List < Table >> GetAllTable() { var tableList = await db.Tables.Include(o => o.Checks.Select(i => i.CheckItems)).ToListAsync(); return tableList; } 

I follow the syntax here is MSDN . However, when I run this code, I get the following error. Does anyone know what's wrong here? Thanks!

InvalidCastException: cannot use an object of type 'Remotion.Linq.Clauses.Expressions.SubQueryExpression' to enter type 'System.Linq.Expressions.MemberExpression'. ** Microsoft.Data.Entity.Query.EntityQueryModelVisitor.b__30_2 (<> f__AnonymousType2`2 <> h__TransparentIdentifier0)

+2
source share
1 answer

The documentation you are reading is for EF 5.

meeting design notes for EF 7 say the syntax for this has changed - try the following:

 db.Tables.Include(t => t.Checks) .ThenInclude(c => c.CheckItems) .ToListAsync() 
+12
source

Source: https://habr.com/ru/post/1238484/


All Articles