以下代码我想使用多个条件,但不支持仅使用一个条件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();
答案 0 :(得分:0)
p.Score<=35 && p.Score <=50
与简单的p.Score<=35
相同。
我想你真的想要
p.Score >= 35 && p.Score <= 50
即分数在35到50之间?
答案 1 :(得分:0)
将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();
答案 2 :(得分:0)
考虑标记列表[15, 30, 35, 45, 50]
现在,按照您在代码中应用的条件,
where p.Score<=35 && p.Score <=50
您将获得[15,30,35]
,因为这些元素同时满足两个条件(<=35
&& <=50
)
您将不会获得[45,50]
,因为它们仅满足一个条件(<=50
)
由于您在两个条件之间都应用了&&
子句,因此标记必须同时通过两个条件才能显示。仅通过一个条件是不够的。
因此,您需要更改where
子句。
where p.Score <=50
where p.Score>=35 && p.Score <=50