I'm trying to write a semi-advanced LINQ to SQL query to search through my entities in a .NET 6 project. The filtering in my LINQ statement looks something like this:
List<string> _searchList = new() {"%a%", "%b%"};
var _query = (from tblHeader in _DbContext.batches
where tblHeader.isDeleted != true
select tblHeader)
_query = _query.Where(x =>
_searchList.All(y =>
EF.Functions.Like(x.Name, y)
)
);
var _results = await _query.ToListAsync();
The Error Looks like:
The LINQ expression 'y => __Functions_1
.Like(
matchExpression: EntityShaperExpression:
FFM.DataAccessModels.App.batches
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.Name,
pattern: y)' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Is it possible to use the LINQ All() (or even the linq Any()) within a Where()? Or is there a better way to write this query?