I've written this query to find orders whose job title is something like "Assistant Manager" or "mit1" or "mit2", etc.
var searchTerms = new List<string> { "manager", "mit" };
var report = await _context.Orders
.Where(x =>
searchTerms.Any(searchTerm => x.JobTitle.Contains(searchTerm))
)
.Select(x => new {
x.Id,
x.JobNumber,
x.JobTitle,
x.DateOrdered
})
.OrderByDescending(x => x.DateOrdered)
.Take(1000)
.ToListAsync();
However, this doesn't translate to SQL. I get this error:
The LINQ expression 'DbSet<Order>
.Where(o => __searchTerms_0
.Any(searchTerm => o.JobTitle.Contains(searchTerm)))' 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().
I understand the principle and will evaluate this on the client if absolutely necessary. But before I do that, is there a way to write this query in a way that will translate to SQL?
I want a single field to contain (not match exactly but merely contain) any of the list of provided strings.