MVC 实体如何获取子集

 ViewBag.List = _questionRepository.GetAllIncluding(s=>s.Selections, p=>p.QuestionCategory,t=>t.Investigations).ToList();

 

      该问题实体GetAllIncluding获取选项子集合,问题分类、关联的问卷集合。

 

      GetAllIncluding与GetAll的区别是,GetAllIncluding明确指明我需查询的实体里的包含的关联表的实体(通过外键)也要查询出来。

 

      GetAllIncluding(s=>s.Selections)是查询问题时,把关联的问题选项也要查询出来。

 

     多个子集合关联,通过逗号区分即可。如GetAllIncluding(s=>s.Selections, p=>p.QuestionCategory,t=>t.Investigations)

posted @ 2018-03-01 11:11  古月木昜  阅读(528)  评论(0编辑  收藏  举报