0

嗨,我是 LINQ 的新手,需要将以下 SQL 转换为 LINQ。有人可以帮我怎么写吗?

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

谢谢

4

1 回答 1

1

也许是这样的:

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

其中 db 是 linq 数据上下文

于 2013-09-05T11:47:16.880 回答