c# - 如何在 linq 中添加多个 where 子句?
问题描述
我有这个查询
db.v_Report_CompanySearches
.Select(x => x.PersonName) //Only return Names
.Distinct() // Make to Unique
.Where(y => y.ToLower().Contains(mPersonName)) //where
.OrderBy(x => x);
我只希望它返回 1 个名为 PersonName 的列,但我想将 where 子句更改为
PersonName.ToLower().Contains(mPersonName) || AccountName.ToLower().Contains(mPersonName)
AccountName 是其中的另一列,但我无法正确使用语法。有谁知道如何改变它?
谢谢
解决方案
将 Where 子句放在 Select 之前
db.v_Report_CompanySearches
.Where(y => y.PersonName.ToLower().Contains(mPersonName) || y.AccountName.ToLower().Contains(mPersonName) ) //where
.Select(x => x.PersonName) //Only return Names
.Distinct() // Make to Unique
.OrderBy(z => z);
推荐阅读
- sql-server - 使用 SQL 分发记录
- typescript - 所有 monorepo 包的单一 TypeScript 配置 + 编译命令
- mysql - 尝试嵌套查询时出现MYSQL Workbench错误
- php - 返回输入数字的错误值
- javascript - 在 Word Javascript API / Office.js 中创建跨越光标前字符的范围
- android-studio - Android工作室:字体没有颜色
- elasticsearch - 使用filebeat中的-E选项从命令行动态输入路径
- android - 错误:不是封闭类:MainActivity
- c# - 为什么 graphql-dotnet 会为此架构返回“预期的非空值”错误?
- javascript - 表单在提交时提交到 Textarea