I want to be able to do a basic search for multiple words. In essence, using LINQ to do the equivalent of the SQL query
SELECT *
FROM table
WHERE column LIKE '%foo%' OR column LIKE '%bar%'
I found a few similar questions on here and they mostly provide the same solution, splitting the input and then using Any
to search for all words. However I get an error when using this solution.
Local sequence cannot be used in LINQ to SQL implementations of query operators except the Contains operator
I understand the error message to mean I cannot use Any
- only Contains
. But this doesn't make sense to me as the solutions on here are successfully using Any
.
This is my code.
var termString = "foo bar";
var searchTerms = termString.Split(' ');
var itemsList = (from items in myDataContext.myDatabaseTable
where searchTerms.Any(term => items.ColumnName.Contains(term))
select items).ToList();