有没有办法在Where子句中循环?

时间:2013-06-21 05:21:17

标签: c# linq

有两个列表"ObjlistA""ObjlistB".

var newList = from someObg i ObglistB
       where [condition = true if some property of any element in the list ObjlistAA equals  someObg's some property]
       select someObg

有没有办法在where子句中循环,以便可以将obj的属性与列表中的每个元素的属性进行比较? 任何人都可以帮我解决“Where”部分吗?

3 个答案:

答案 0 :(得分:4)

这是你要找的吗?

var newList = ObjlistB.Where(someObj => ObjlistA.Any(a => a.SomeProperty == someObj.SomeProperty))

答案 1 :(得分:0)

where ObjlistA.Any(x => x.Property == someObj.Property)

答案 2 :(得分:0)

你的意思是?

    var newList = from someObg in ObjlistB
                  where ObjlistA.Any(a => a.ID == someObg.ID)
                  select someObg;
相关问题