linq - EF.Functions.Contains 包括多个关键字

标签 linq asp.net-core entity-framework-core

我需要搜索多个列(LearningModuleDesc 和 LearningModuleContent,它们使用下面的 || 语句工作),但我还需要搜索多个关键字。 .Net Core 2.2 和 EF Core 不支持包含 Contains 的字符串数组(如下例所示),但是一些关于我如何处理这个问题的指导会很棒。

string[] stringarray = new string[] { "mill", "smith" };

var results =  _context.LearningModules
.Where(x => EF.Functions.Contains(x.LearningModuleDesc, stringarray)
|| EF.Functions.Contains(x.LearningModuleContent, stringarray)
);

最佳答案

如果我没理解错的话,你正在寻找这样的东西

 var results = _context.LearningModules.Where(
   x => stringarray.Any(t => x.LearningModuleDesc.Contains(t)) || 
        stringarray.Any(t => x.LearningModuleContent.Contains(t)))

关于linq - EF.Functions.Contains 包括多个关键字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55230001/

相关文章:

c# - Entity Framework Core 尝试在调用 SaveChanges() 时插入重复记录

c# - 将 Lambda 函数转换为 Lambda 表达式

c# - Linux Entity Framework Core 上的无效 SQL Server 连接字符串

node.js - AggregateException : One or more errors occurred.(发生一个或多个错误。(无法启动 'npm'。要解决此问题:

c# - 如何在 asp.net-core-2.0 中的项目中添加 'IDesignTimeDbContextFactory<DataContext>' 的实现

c# - EF Core 2.0.0 查询过滤器正在缓存 TenantId(针对 2.0.1+ 更新)

c# - Linq ThenBy 可能为空

c# - 在字典中选择特定对象类型并将其删除的最有效方法

c# - 确定是否通过了具体值或表达式?

c# - 如何用修饰的实现覆盖作用域服务?