.Where(i => strArray.Any(s => i.Name.Contains(s)))
I have an array of strings [ "text1", "text2", "text3"] and I want to find all Names that have a substring such as: text1somethingsomething
The error I get is
System.InvalidOperationException: The LINQ expression 's => EntityShaperExpression:
SalonML_API.Data.Models.DynamicContent
ValueBufferExpression:
ProjectionBindingExpression: EmptyProjectionMember
IsNullable: False
.Name.Contains(s)' 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.
at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitLambda[T](Expression`1 lambdaExpression)
My full code is
[HttpGet]
public async Task<IActionResult> GetContent([FromQuery] string[]? strArray)
{
// ** todo get this to order by OrderIndex **
List<DynamicContentDTO> dynContentList;
if (strArray == null)
dynContentList = await _context.DynamicContents
.OrderBy(x => x.OrderIndex)
.Select(d => new DynamicContentDTO(d))
.ToListAsync();
else
dynContentList = await _context.DynamicContents
.OrderBy(x => x.OrderIndex)
.Where(i => strArray.Any(s => i.Name.Contains(s)))
.Select(d => new DynamicContentDTO(d))
.ToListAsync();
return Ok(dynContentList);
}