C# 无法在简单查询中转换LINQ表达式

C# 无法在简单查询中转换LINQ表达式,c#,linq,entity-framework-core,C#,Linq,Entity Framework Core,你好,谢谢你的帮助。我连接到一个SQL表,该表包含一个名为“company”的字段,该字段是公司的名称。我想做的是,我有一个单词数组(或我想搜索的单词列表,例如: List<string> WordsToSearch = new List<string>() { "shabab", "motor", "sales" }; 但我得到的是如下错误: The LINQ expression 'DbSet<Acc

你好,谢谢你的帮助。我连接到一个SQL表,该表包含一个名为“company”的字段,该字段是公司的名称。我想做的是,我有一个单词数组(或我想搜索的单词列表,例如:

List<string> WordsToSearch = new List<string>() { "shabab", "motor", "sales" };
但我得到的是如下错误:

The LINQ expression 'DbSet<Account>
.Where(a => __palabras_0
    .All((Func<string, bool>)(MethodInfo)Boolean Contains(System.String).CreateDelegate(
        delegateType: (Type)System.Func`2[System.String,System.Boolean], 
        target: a.Company)))' 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().
var search = await mydb.Accounts.ToListAsync(); 
var test = search.Where(w => WordsToSearch.All( w.Company.Contains ) );

结果没有问题,请告诉我为什么会出现此错误?或者我做错了什么?非常感谢您的帮助!

您面临的问题是,您的请求具有无法直接用SQL语言(或服务器端)表示的条件搜索。应将数据提取到可枚举对象(如列表)中即使是异步的,条件也应该在客户端(您的程序)中进行评估。请注意您将面临的性能问题,因为没有通过索引或数据库提供的任何帮助进行加速。

您的错误消息是非常自我解释的。
mydb.Accounts.Where(w=>WordsToSearch.Contains(w.Company))您是否尝试过:
mydb.Accounts.Where(w=>WordsToSearch.Contains(w.Company)).ToListAsync();
mydb.Accounts.Where(w=>WordsToSearch.Any(x=>x==w.Company)).ToListAsync();
var search=wait mydb.Accounts.Where(a=>WordsToSearch.All(w=>a.Company.Contains(w)).ToListAsync();
也可以工作
var search = await mydb.Accounts.ToListAsync(); 
var test = search.Where(w => WordsToSearch.All( w.Company.Contains ) );