How to include() nested child entity in linq

前端 未结 4 396
日久生厌
日久生厌 2020-12-03 04:17

How do I include a child of a child entitiy?

Ie, Jobs have Quotes which have QuoteItems

var job = db.Jobs
            .Where(x => x.JobID == id)
          


        
4条回答
  •  生来不讨喜
    2020-12-03 05:10

    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)

提交回复
热议问题