Entity Framework - Include Multiple Levels of Properties

前端 未结 8 848
囚心锁ツ
囚心锁ツ 2020-11-22 08:43

The Include() method works quite well for Lists on objects. But what if I need to go two levels deep? For example, the method below will return ApplicationServers with the i

8条回答
  •  感动是毒
    2020-11-22 09:00

    I also had to use multiple includes and at 3rd level I needed multiple properties

    (from e in context.JobCategorySet
                          where e.Id == id &&
                                e.AgencyId == agencyId
                          select e)
                          .Include(x => x.JobCategorySkillDetails)
                          .Include(x => x.Shifts.Select(r => r.Rate).Select(rt => rt.DurationType))
                          .Include(x => x.Shifts.Select(r => r.Rate).Select(rt => rt.RuleType))
                          .Include(x => x.Shifts.Select(r => r.Rate).Select(rt => rt.RateType))
                          .FirstOrDefaultAsync();
    

    This may help someone :)

提交回复
热议问题