如何获取所有包含给定单词的所有字符串?

时间:2019-12-10 18:14:11

标签: c# entity-framework-core

我试图获取属性包含字符串列表中任何一个的所有行。我正在尝试这种方式:

string myWordsToSearch = "word1 word2 word3";
List<string> miLstWords = myWordsToSearch
    .Split(" ")
    .Where(x => string.IsNullOrWhiteSpace(x) == false)
    .ToList();
MyDbContext.MyDbSet.Where(x => miLstWords.Any(y => x.MyPropertyInDbSet.Contains(y)));

但是我得到了这个例外:

  

发生一个或多个错误。 (LINQ表达式'Where(       来源:DbSet,       谓词:(s)=> Any(           来源:(未处理的参数:__ miLstWords_0),           谓词:(y)=> MyPropertyInDbSet.Contains(y)))'无法翻译。可以采用以下形式重写查询:   翻译,或通过插入   调用AsEnumerable(),AsAsyncEnumerable(),ToList()或   ToListAsync()。有关详情,请参见https://go.microsoft.com/fwlink/?linkid=2101038   更多信息。

我正在使用Entity Core 3.0。

0 个答案:

没有答案