EF LINQ include multiple and nested entities

后端 未结 6 1160
猫巷女王i
猫巷女王i 2020-11-28 03:25

Ok, I have tri-leveled entities with the following hierarchy: Course -> Module -> Chapter

Here was the original EF LINQ statement:

Course course = db         


        
6条回答
  •  暖寄归人
    2020-11-28 04:02

    Include is a part of fluent interface, so you can write multiple Include statements each following other

     db.Courses.Include(i => i.Modules.Select(s => s.Chapters))
               .Include(i => i.Lab)
               .Single(x => x.Id == id); 
    

提交回复
热议问题