Error
LINQ to Entities does not recognize the method 'Boolean ContainsAny(System.String, System.String[])' method, and this method cannot be translated into a store expression.
Code
var predicate = FilterClients(clientRequest);
clients = db.Clients.Where(predicate).Include(x => x.Organization)
.Include(x => x.Department).ToList();
private Expression<Func<Client, bool>> FilterClients(ClientRequest clientRequest)
{
var predicate = PredicateBuilder.True<Client>();
if (clientRequest.IsBySearchPatternFullName)
{
var searchPatternFullName = clientRequest.SearchPatternFullName.Trim();
var matches = Regex.Matches(searchPatternFullName, @"\w+[^\s]*\w+|\w");
var words = new List<string>();
foreach (Match match in matches)
{
var word = match.Value;
words.Add(word);
}
var wordArray = words.ToArray();
predicate = predicate.And(x => x.LastName.ContainsAny(wordArray) || x.FirstName.ContainsAny(wordArray) || x.MiddleName.ContainsAny(wordArray));
}
return predicate;
}
There is similar question C# LINQ to Entities does not recognize the method 'Boolean'
But I would like to optimize this part somehow
predicate = predicate.And(x => x.LastName.ContainsAny(wordArray) || x.FirstName.ContainsAny(wordArray) || x.MiddleName.ContainsAny(wordArray));
Any clue people?