Select multiple nested levels of child tables in Entity Framework Core

Also, the .ThenInclude intellisense for only works up to the 3rd level, for example:

_Context.A.Include(a => a.B).ThenInclude(B => B.C).ThenInclude(C => C.D)

The last part of that statement:

 .ThenInclude(C => C.D)

won't show "D", so you have to type D in yourself, then wait for a short period of time for the compilation error to disappear!


You can use the keyword ThenInclude instead

e.g.

var company = context.Companies
             .Include(co => co.Employees).ThenInclude(emp => emp.Employee_Car)
             .Include(co => co.Employees).ThenInclude(emp => emp.Employee_Country)
             .FirstOrDefault(co => co.companyID == companyID);