LINQ to Entities无法识别方法Boolean ContainsAny [英] LINQ to Entities does not recognize the method Boolean ContainsAny
本文介绍了LINQ to Entities无法识别方法Boolean ContainsAny的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
错误
LINQ to Entities无法识别方法'Boolean ContainsAny(System.String,System.String [])'方法,以及此方法 无法转换为商店表达式.
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.
代码
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;
}
存在类似的问题 C#LINQ实体无法识别方法布尔"
但是我想以某种方式优化这部分
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));
有线索的人吗?
推荐答案
哦!我刚刚做到了!
foreach (Match match in matches)
{
var word = match.Value;
predicate = predicate.And(x => x.LastName.Contains(word) || x.FirstName.Contains(word) || x.MiddleName.Contains(word));
}
这篇关于LINQ to Entities无法识别方法Boolean ContainsAny的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文