Rahul Katte
Rahul Katte

Reputation: 9

Is there a way to loop inside Where clause?

There are two lists "ObjlistA" and "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

Is there a way to loop inside the where clause, so that the obj's property can be compared with each and every element's property in the list? Can anyone help me out the "Where" part?

Upvotes: 0

Views: 660

Answers (3)

Rob Hruska
Rob Hruska

Reputation: 120286

Is this what you're looking for?

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

Upvotes: 4

ojlovecd
ojlovecd

Reputation: 4892

you mean this?

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

Upvotes: 0

Ed Swangren
Ed Swangren

Reputation: 124642

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

Upvotes: 0

Related Questions