The below code I want to use more than one condition but it is not supporting it is taking only one condition only p.score<=35 it is only displaying all records but p.score<=50 this condition applicable record is not dispying how can I resolve this issue.

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

3 Answers

0
user10103607 On Best Solutions

Consider a list of marks [15, 30, 35, 45, 50]

Now as per the condition which you have applied in your code, where p.Score<=35 && p.Score <=50

you will get [15,30,35] because these elements satisfy both conditions (<=35 && <=50)

you will not get [45,50] as these satisfy only one condition (<=50)

Since you have applied && clause in between both conditions, the marks need to pass both conditions in order to be displayed. Passing only one condition is not enough.

Therefore, you need to change your where clause.

  1. If you want to display all those marks which are less than or equal to 50, you need to write where p.Score <=50
  2. If you want to display only those marks which are less than or equal to 50 but greater than or equal to 35, you need to write where p.Score>=35 && p.Score <=50
0
user1987392 On
p.Score<=35 && p.Score <=50

Is the same as simply p.Score<=35.

I assume you actually want

p.Score >= 35 && p.Score <= 50

i.e. score between 35 and 50?

0
Mehmet Ordu On

Change p.Score<=35 && p.Score <=50 to (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();