Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.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# 从集合A获取对象,其中A的ID存在于B对象集合中_C#_Linq - Fatal编程技术网

C# 从集合A获取对象,其中A的ID存在于B对象集合中

C# 从集合A获取对象,其中A的ID存在于B对象集合中,c#,linq,C#,Linq,我有一个person对象的集合,person有一个名为“ID”的属性。 我还有一个personcountry对象的集合B,personcountry对象有一个属性personId 现在我想选择集合A中的所有人员,集合B中有一个对象及其personId 有了这些数据 person (collection A List[Person]) person id name 1 John 2 John 3 John2 4 Pete

我有一个person对象的集合,person有一个名为“ID”的属性。 我还有一个personcountry对象的集合B,personcountry对象有一个属性personId

现在我想选择集合A中的所有人员,集合B中有一个对象及其personId

有了这些数据

person (collection A List[Person]) 
person id  name
    1      John
    2      John
    3      John2
    4      Pete
    5      Bill
    6      Samantha
和此集合B(列表[国家])

我想要集合A中id为1、3和5的个人记录

我确实用intersect方法处理了两个INT集合,但在使用这两个对象集合时,我遇到了麻烦。

我会进行连接

 var q = Persons.Where(p => Countries.Any(c => p.Id== c.PersonId))
var query = (from p in persons
            join pc in personcountry on p.Id equals pc.PersonId
            select p).AsEnumerable();
我想加入

var query = (from p in persons
            join pc in personcountry on p.Id equals pc.PersonId
            select p).AsEnumerable();