where 条件不支持多于 1 个条件
where condition not supporting more than 1 condition
下面的代码我想使用多个条件但它不支持它只采用一个条件p.score<=35
它只显示所有记录但是p.score<=50
这个条件适用的记录是没有发现我该如何解决这个问题。
cs=(from e in db.Students
join p in db.Marks
on e.S_ID equals p.S_ID
join t in db.Details
on p.School_ID equals t.School_ID
where p.Score<=35 && p.Score <=50
select new MyModel
{
S_Name = e.S_Name,
Score = (int)p.Score,
Status = p.Status,
Address_City = t.Address_City,
Email_ID = t.Email_ID,
Accomplishments = t.Accomplishments
}).ToList();
p.Score<=35 && p.Score <=50
与 p.Score<=35
相同。
我假设你真的想要
p.Score >= 35 && p.Score <= 50
即得分在 35 到 50 之间?
将 p.Score<=35 && p.Score <=50 更改为 (p.Score>=35 && p.Score <=50).
cs=(from e in db.Students
join p in db.Marks
on e.S_ID equals p.S_ID
join t in db.Details
on p.School_ID equals t.School_ID
where (p.Score>=35 && p.Score <=50)
select new MyModel
{
S_Name = e.S_Name,
Score = (int)p.Score,
Status = p.Status,
Address_City = t.Address_City,
Email_ID = t.Email_ID,
Accomplishments = t.Accomplishments
}).ToList();
考虑一个标记列表 [15, 30, 35, 45, 50]
现在根据您在代码中应用的条件,
where p.Score<=35 && p.Score <=50
你会得到[15,30,35]
因为这些元素同时满足两个条件(<=35
&& <=50
)
你不会得到 [45,50]
因为它们只满足一个条件 (<=50
)
由于您在两个条件之间应用了 &&
子句,标记需要同时满足两个条件才能显示。只通过一个条件是不够的。
因此,您需要更改 where
子句。
- 如果要显示所有小于等于50的标记,需要写成
where p.Score <=50
- 如果只显示小于或等于50但大于或等于35的标记,则需要写
where p.Score>=35 && p.Score <=50
下面的代码我想使用多个条件但它不支持它只采用一个条件p.score<=35
它只显示所有记录但是p.score<=50
这个条件适用的记录是没有发现我该如何解决这个问题。
cs=(from e in db.Students
join p in db.Marks
on e.S_ID equals p.S_ID
join t in db.Details
on p.School_ID equals t.School_ID
where p.Score<=35 && p.Score <=50
select new MyModel
{
S_Name = e.S_Name,
Score = (int)p.Score,
Status = p.Status,
Address_City = t.Address_City,
Email_ID = t.Email_ID,
Accomplishments = t.Accomplishments
}).ToList();
p.Score<=35 && p.Score <=50
与 p.Score<=35
相同。
我假设你真的想要
p.Score >= 35 && p.Score <= 50
即得分在 35 到 50 之间?
将 p.Score<=35 && p.Score <=50 更改为 (p.Score>=35 && p.Score <=50).
cs=(from e in db.Students
join p in db.Marks
on e.S_ID equals p.S_ID
join t in db.Details
on p.School_ID equals t.School_ID
where (p.Score>=35 && p.Score <=50)
select new MyModel
{
S_Name = e.S_Name,
Score = (int)p.Score,
Status = p.Status,
Address_City = t.Address_City,
Email_ID = t.Email_ID,
Accomplishments = t.Accomplishments
}).ToList();
考虑一个标记列表 [15, 30, 35, 45, 50]
现在根据您在代码中应用的条件,
where p.Score<=35 && p.Score <=50
你会得到[15,30,35]
因为这些元素同时满足两个条件(<=35
&& <=50
)
你不会得到 [45,50]
因为它们只满足一个条件 (<=50
)
由于您在两个条件之间应用了 &&
子句,标记需要同时满足两个条件才能显示。只通过一个条件是不够的。
因此,您需要更改 where
子句。
- 如果要显示所有小于等于50的标记,需要写成
where p.Score <=50
- 如果只显示小于或等于50但大于或等于35的标记,则需要写
where p.Score>=35 && p.Score <=50