繁体   English   中英

如何在linq中添加多个where子句?

[英]How to add multiple where clauses in linq?

我有这个查询

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);

我只希望它返回名为PersonName的1列,但我想将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);

你应该将SelectWhere

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(x => x);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM