How to include() nested child entity in linq

前端 未结 4 395
日久生厌
日久生厌 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:09

    This did the trick for me as @flindeberg said here . Just added checking if there are children in each parent item in the list

     List companies = dbCtx.Companies.Where(x=>x.CompanyBranches.Count > 0)
                                .Include(c => c.CompanyBranches)
                                .Include("CompanyBranches.Address")
                                .ToList();
    

提交回复
热议问题