我有这个问题:
SELECT * FROM ScheduleGroups A
INNER JOIN ScheduleGroupResources B ON A.ScheduleGroupId=B.ScheduleGroupId
WHERE B.ScheduleGroupId IN (SELECT ScheduleGroupId
FROM ScheduleGroupResources
WHERE ScheduleResourceId=2)
我想用DbContext查询表示。
目前:
return actualContext.ScheduleGroups
.Include(a => a.ScheduleGroupResources).ToList();
这给我带来了所有结果。我只是想在'where'中显示过滤。
非常感谢你的一切!
编辑:
我找到了解决方案:
return actualContext.ScheduleGroups
.Include(a => a.ScheduleGroupResources)
.Where(a => a.ScheduleGroupResources.Any(b => b.ScheduleResourceId == scheduleResourceId)).ToList();
答案 0 :(得分:0)
仅供参考,原始查询可以写成:
SELECT *
FROM ScheduleGroups A
INNER JOIN ScheduleGroupResources B ON A.ScheduleGroupId=B.ScheduleGroupId
WHERE ScheduleResourceId=2