Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.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
Sql 使用实体框架过滤数据_Sql_Entity Framework_Linq_Entity Framework 6 - Fatal编程技术网

Sql 使用实体框架过滤数据

Sql 使用实体框架过滤数据,sql,entity-framework,linq,entity-framework-6,Sql,Entity Framework,Linq,Entity Framework 6,我正在努力获取正确的数据 房间桌子 Id | Name 1 Room1 2 Room2 资源表 Id | Name 1 Resource1 2 Resource2 3 Resource3 Id | RoomId | ResourceId 1 1 1 2 1 2 3 1 3 4 2 2 5 2 3 RoomResources表 Id

我正在努力获取正确的数据

房间桌子

Id | Name
1    Room1
2    Room2
资源表

Id | Name
1    Resource1
2    Resource2
3    Resource3
Id | RoomId | ResourceId
1      1         1
2      1         2
3      1         3
4      2         2
5      2         3
RoomResources表

Id | Name
1    Resource1
2    Resource2
3    Resource3
Id | RoomId | ResourceId
1      1         1
2      1         2
3      1         3
4      2         2
5      2         3
我想选择一个包含Resource1和Resource2的房间 我正在使用这个代码

int[] ids = sResources.Split(',').Select(s => int.Parse(s)).ToArray();

rooms = from r in context.Rooms
    where r.Area.Office.Id == officeId
    && r.MaximumPeople >= numberOfPeople
    && r.RoomResources.Any(s => ids.Contains(s.ResourceId))
    select r;
但是它返回Room1和Room2,结果应该是Room1,也许是这样

int[] ids = sResources.Split(',').Select(s => int.Parse(s)).ToArray();

rooms = from r in context.Rooms
    where r.Area.Office.Id == officeId
    && r.MaximumPeople >= numberOfPeople
    && ids.All(i => r.RoomResources.Any(s => s.ResourceId == i)) // try this here
    select r;