Reputation: 3740
Hi I'm new to LINQ and got a requirement to convert below SQL into LINQ. Can someone help me how to write it?
select emp.id, emp.name from employee emp
left join department dept on dept.id = emp.deptid
and (emp.managerid = '001' or (emp.manager in (select managerid from manager where location Contains('l001','l002','l003') and state =1)))
Thanks
Upvotes: 0
Views: 81
Reputation: 31239
Maybe something like this:
var locationIds = new List<string> {"l001", "l002", "l003"};
var ls=(
from emp in db.employee
from dept in db.department
.Where(a=>a.id == emp.deptid).DefaultIfEmpty()
where (emp.managerid == "001"
|| db.manager.Where(w=>locationIds.Contains(w.location) && w.state == 1)
.Select(s=>s.managerid).Contains(emp.manager))
select new
{
emp.id,
emp.name
}
).ToList();
Where db is the linq data context
Upvotes: 1