我有这段代码:
using (Entities db = new Entities())
{
refer = db.Refferals.Where(r =>
r.RefferalDetails.Any(rd =>
(Name.Contains(rd.Name) || rd.Name.Contains(Name) || LastName.Contains(rd.LastName) || rd.LastName.Contains(LastName)
|| Company.Contains(r.Company) || r.Company.Contains(Company)
Mobile.Contains(rd.Mobile) || rd.Mobile.Contains(Mobile))) &&
Mobile.Length > 9 && Name.Length > 1 && LastName.Length > 1 && Company.Length > 2
).ToArray();
}
虽然括号计数是正确的,但编辑提供了一个额外的parantheses。
我尝试重新启动Visual Studio,但它一样。
答案 0 :(得分:3)
尝试在||
和r.Company.Contains(Company)
之间添加缺少的Mobile.Contains(rd.Mobile)
。
修复缩进,这样可以更容易地看出错误。当我缩进它时,失踪的操作员像拇指一样伸出来,很容易看出这些parens是如何工作的。
using (Entities db = new Entities())
{
refer = db.Refferals.Where(r =>
r.RefferalDetails.Any(rd =>
(
Name.Contains(rd.Name)
|| rd.Name.Contains(Name)
|| LastName.Contains(rd.LastName)
|| rd.LastName.Contains(LastName)
|| Company.Contains(r.Company)
|| r.Company.Contains(Company)
|| /* <-- ADDED OR OPERATOR HERE */
Mobile.Contains(rd.Mobile)
|| rd.Mobile.Contains(Mobile)
)
)
&& Mobile.Length > 9
&& Name.Length > 1
&& LastName.Length > 1
&& Company.Length > 2
).ToArray();
}
答案 1 :(得分:1)
在Mobile.Contains(rd.Mobile)之前缺少一个** || **
refer = db.Refferals.Where
(
r => r.RefferalDetails.Any
(
rd =>
(
Name.Contains(rd.Name) || rd.Name.Contains(Name) || LastName.Contains(rd.LastName) || rd.LastName.Contains(LastName)
|| Company.Contains(r.Company) || r.Company.Contains(Company)
|| Mobile.Contains(rd.Mobile) || rd.Mobile.Contains(Mobile)
)
)
&& Mobile.Length > 9 && Name.Length > 1 && LastName.Length > 1 && Company.Length > 2
).ToArray();
答案 2 :(得分:0)
如果没有运行代码,你似乎会做某种一元选择(rd)。我建议你开始重构代码并将每个条件分解为一部分...