我正在尝试获取正确的数据
客房表
Id | Name
1 Room1
2 Room2
资源表
Id | Name
1 Resource1
2 Resource2
3 Resource3
RoomResources表
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
答案 0 :(得分:0)
也许这个?
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;