I have a situation where i have Keyword column in table which contains comma separated keywords. User can provide multiple search terms to search against the Keyword column. For example user provides the below search terms “one,two,three” and the db column may contain any of the “one” ,”two”, “three” or none of them. how can I write a query which matches against any of the provided search term.
I have tried the below
string[] searchTerm = {"one","two","three"};
query =Product.Where( p=> searchTerm.Any(val => p.Keywords.Contains(val)));
and
var query=db.Products;
foreach (string searchword in searchTerm)
{
query = query.Where(c => c.Keywords.Contains(searchword ));
}
but its not working for me.
Thanks,
If you split the text provided by the user in different keywords, as in converting “one,two”,three” in a string[], you could do something like:
Example:
Prints: