Reputation: 702
I have list of strings like "one" , "two" , "three",
I want to search from a database and select all items that have at least one of them , I want do this by entity framework. To do this I use:
if (SearchVM.Tags.Count > 0)
//SourceList= SourceList.Where(x=>x.Tags.Where(...));
It doesn't work because it's wrong and incomplete.
By T-sql is :
select * from SourceList where tagname in (select name from SearchList)
Upvotes: 0
Views: 40
Reputation: 39366
Try this:
var SearchList= new List<string>{"one" , "two" , "three" };
var result = dataContext.SourceList.Where(p => p.Tags.Any(t => SearchList.Contains(t.TagName)));
Contains
will be translated to IN
statement
Upvotes: 2