I have a case where a user is allowed to supply a set of keywords (more preceisely substrings) when searching for a user name.
I have something like
// this set of strings should find names such as john, mary or smith
List<string> searchStrings=new List<string>(){"jo","ma","th"};
// LINQ query looks like this
var filteredPatients=allPatients.Where(p =>
(searchStrings.Any(s=>p.Name.ToLower().Contains(s)));
However this fails and gives the exception:
System.AggregateException : One or more errors occurred. (The LINQ expression could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync()
This is running against entityFramework, .NET Core 3.1 against a Postgres Db
Is there another way to write this query to produce the desired result?
NOTE: it would be possible to call ToList() or ToArray() on allPaitents but I would like to avoid this as the whole (very large) table will be read into memory.