You can use Intersect + Any :
query = query.Where(x => x.Tags.Intersect(tagList).Any());
This suggests that Tags actually an IEnumerable<string> or other type that overrides Equals + GetHashCode . If this is not the case, you can provide a custom IEqualityComparer<Tag> for Intersect .
So tagList is a List<string> for the current page. But if you want to list all those that have one or more tags along with a list of tags on all pages, so IEnumerable<List<string>> , you can use SelectMany to flatten them:
query = query.Where(x => x.Tags.Intersect(allTagLists.SelectMany(list => list)).Any());
If Intersect not supported by your LINQ provider, you can use the following approach:
query = query.Where(x => x.Tags.Any(t => tagList.Contains(t)));
This is less efficient in LINQ-To-Objects since it does not use a set.
source share