我有这个查询
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是那里的另一列,但是我语法不正确。有人知道如何更改吗?
谢谢
答案 0 :(得分:5)
将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);
答案 1 :(得分:1)
您应该将Select
移到Where
之后:
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);