tags:

views:

69

answers:

3

i have a list of filter names: FILTERBYNAMES

my query result items each contain a name list: NAMES

I want to filter the result an take all items whose name list contains at least one name in the FILTERNAMELIST:

   results= result.where(r=>r.NAMES.CONTAINS(...?)...?
+3  A: 

I think you need something like:

var results = list.Where(i => i.Names
                               .Any(name => filterNameList.Contains(name)));
Mehrdad Afshari
+4  A: 

You can solve this by looking at the intersection of the two name sets.

var filteredResult = result.Where(i => i.Names.Intersect(filter).Any());
Daniel Brückner
+1  A: 

To limit the enumerations of the filter, you could use a hashset...

HashSet<string> hashedFilter = new HashSet<string>(filterByNames);

var results = result
  .Where(x => x.Names
    .Any(name => hashedFilter.Contains(name))
  );
David B