c# - Using LINQ when my where clause will contain a LIST -


i have list trying query using linq. t type has property list < u >. trying query list < t >'s list < u > property pull objects who's list property items match items in seperate list < u > have built filtering. code looks this:

class t {    list<u> names; }  class u {  }  //then want query list of t interrogating t objects' names property has same items have list < u > have created.  list<u> searchtermitems; list<t> allobjects;  //query allobjects , find out objects' name property items match items in searchtermitems list 

you use enumerable.intersect:

var filtered = allobjects.intersect(searchtermitems); 

because working collection of lists rather single list, in order acheive desired output need use enumerable.where in conjunction enumerable.intersect:

var filtered = allobjects.where(x => x.names.intersect(searchtermitems).any()); 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -