How to check multiple cases in Linq ( to classify "over paid","under paid","medium pay")
Sql
select id,name,salary,
case when salary <=1500 then 'under paid'
when salary >=3500 then 'over paid'
else 'medium pay' end as status
from Person
Linq
var q =
context.Persons.
Select(c =>
new {
EmployeeID = c.Id,
EmployeeName = c.name,
EmployeeSalary = c.salary,
Status = c.salary > 1000 ? "under paid" : "overpaid"
}
);
Using ternary operator i can check either or cases.otherwise i have to use if..else if.