我有以下实体(伪代码以节省空间)
Program [ int Id,
string Name,
List<ProgramFoodType> ProgramFoodTypes,
List<ProgramFood> ProgramFoods]
ProgramFoodType[ int Id, int ProgramId, int Type, bool IsActive]
ProgramFood [ int Id, int ProgramId, Food Food, FoodType FoodType]
Food [int Id, string Name]
FoodType [int Id, string Name]
我的任务是获取单个带有相关联的ProgramFoodTypes的Program,其中ProgramFoodType应该是活动的,并且还需要与相关实体Food和FoodType的ProgramFoods一起使用。 到目前为止,我已经使用了以下内容: 1- 下面的查询将检索ProgramFoodTypes和ProgramFoods的详细信息,但它会带来所有活动和非活动的ProgramFoodTypes。
var program = mEntities.Programs
.Include(p =>p.ProgramFoodTypes)
.Include(p =>p.ProgramFoods.Select(f =>f.Food))
.InClude(p =>p.ProgramFoods.Select( f =>f.FoodType))
.Where(m =>m.Id== Id);
2- 以下查询将检索详细信息,但缺少Food
和FoodType
var program = (from p in mEntities.Programs
where p.Id ==Id
select new {
Program = p,
ProgramFoodTypes = from pf in p.ProgramFoodTypes
where pf.IsActive
select pf,
ProgramFoods = p.ProgramFoods // here i can't add include statement
}).ToArray().Select(m => m.Program);
如何在第二个查询中包含食物和食品类型?