Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 实体框架-如何基于桥接表值查询对象?_C# 4.0_Entity Framework 4 - Fatal编程技术网

C# 4.0 实体框架-如何基于桥接表值查询对象?

C# 4.0 实体框架-如何基于桥接表值查询对象?,c#-4.0,entity-framework-4,C# 4.0,Entity Framework 4,首先,关于我的表格设置: Group: groupId - int groupName - varchar Schedule: scheduleId - int scheduleName - varchar Group_Schedules scheduleId - int/fk to Schedule groupId - int/fk to Group 我使用的是EF,在上面的场景中,没有创建任何EF实体来表示Group_计划,而是将集合添加

首先,关于我的表格设置:

Group:
    groupId - int
    groupName - varchar

Schedule:
    scheduleId - int
    scheduleName - varchar

Group_Schedules
    scheduleId - int/fk to Schedule
    groupId - int/fk to Group
我使用的是EF,在上面的场景中,没有创建任何EF实体来表示Group_计划,而是将集合添加到表示另一端的Group和Schedule表中

我需要获取属于某个计划的所有组,并将我的返回值设置为
IQueryable
。即(不,这不起作用,因为EF生成桥接表的方式):


是否有一种优雅的方法来获取我需要的数据?

这两种方法都将返回一个
IQueryable

var g = from g in context.Groups
        where g.Group_Schedule.scheduleId = 1 // This doesn't work because Group_Schedule is a collection of Schedule
        select g;
var groups = from g in db.Groups
             where g.Schedules.Any(s => s.scheduleId == 1)
             select g;

var groups = (from s in db.Schedules
              where s.scheduleId == 1
              select s.Groups).SelectMany(g => g);