How to include() nested child entity in linq

The method in the accepted answer doesn't work in .NET Core.

For anyone using .NET Core, while the magic string way does work, the cleaner way to do it would be ThenInclude:

var job = db.Jobs
        .Where(x => x.JobID == id)
        .Include(x => x.Quotes)
        .ThenInclude(x => x.QuoteItems)
        .SingleOrDefault();

(source)


To get a job and eager load all its quotes and their quoteitems, you write:

var job = db.Jobs
        .Include(x => x.Quotes.Select(q => q.QuoteItems))
        .Where(x => x.JobID == id)
        .SingleOrDefault();

You might need SelectMany instead of Select if QuoteItems is a collection too.

Note to others; The strongly typed Include() method is an extension method so you need to include using System.Data.Entity; at the top of your file.