Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.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# LINQ-查找给定列表中的所有项都包含在icollection中的所有记录_C#_List_Linq_Collections - Fatal编程技术网

C# LINQ-查找给定列表中的所有项都包含在icollection中的所有记录

C# LINQ-查找给定列表中的所有项都包含在icollection中的所有记录,c#,list,linq,collections,C#,List,Linq,Collections,我有一个过滤器列表,我想用它来查询一个表,其中返回的项包含所有值,而不仅仅是一个值 该表称为“组织”,包含该组织针对的年龄组列表 public class Organisation { public int OrganisationID { get; set; } public string OrgName { get; set; } public ICollection<OrgAgeGroup> AgeGroupCollection { get; set; } } 最后,从复选框

我有一个过滤器列表,我想用它来查询一个表,其中返回的项包含所有值,而不仅仅是一个值

该表称为“组织”,包含该组织针对的年龄组列表

public class Organisation
{
public int OrganisationID { get; set; }
public string OrgName { get; set; }
public ICollection<OrgAgeGroup> AgeGroupCollection { get; set; }
}
最后,从复选框中选择的值存储在int列表中:

List<int> selectedAges 
列出所选日期
我使用以下代码选择包含任何选定日期的所有组织:

IQueryable<Organisation> orglist = GetAllOrgs();

 orglist = orglist.Where(o => o.AgeGroupCollection.Any(l => selectedAges.Contains(l.AgeGroupID)));
IQueryable orglist=GetAllOrgs();
orglist=orglist.Where(o=>o.AgeGroupCollection.Any(l=>selectedAges.Contains(l.AgeGroupID));

但我不知道如何获取包含所有选定年龄的所有Org。将Any改为All似乎对搜索没有影响。有什么想法吗?

下面的查询应该会给出您想要的

orglist = orglist.Where(
    o => selectedAges.All(
        s => o.AgeGroupCollection
            .Select(l => l.AgeGroupID)
            .Contains(s)));
您需要组织
o
,其中所有
选定的日期
s
都包含在
o
AgeGroupCollection
AgeGroupId
集合中

orglist = orglist.Where(
    o => selectedAges.All(
        s => o.AgeGroupCollection
            .Select(l => l.AgeGroupID)
            .Contains(s)));