Reputation: 13766
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(...?)...?
Upvotes: 1
Views: 375
Reputation: 110221
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))
);
Upvotes: 1
Reputation: 59705
You can solve this by looking at the intersection of the two name sets.
var filteredResult = result.Where(i => i.Names.Intersect(filter).Any());
Upvotes: 4
Reputation: 422280
I think you need something like:
var results = list.Where(i => i.Names
.Any(name => filterNameList.Contains(name)));
Upvotes: 5