日期:2014-05-20  浏览次数:20926 次

请教一个三表联合查询的linq语句,我自己实在写不出来了,谢谢
select id,projectname from projects (项目表)
select id,empName,phone from employees (员工表)

select id,projectid,employeeid,projectRote from project_employee (项目与员工的关系表,projectRote 字段是员工在项目角色)


需要实现如下效果:
传入一个项目ID(16),返回该项目的参与者和在项目中的角色
select empName,phone,projectname,projectrote from projects p,employees e,project_employee pe 
where pe.projectid=16 and e.id=pe.employeeid and p.id=16


请问这个用LINQ怎么实现这个语句?谢谢了!

------解决方案--------------------
有没有外键,有外键直接从 project_employee 入手
C# code

var query = from pe in project_employee
            where pe.id == 16
            select new { pe.employees.empName, pe.projectRote };

------解决方案--------------------
var query=from p in projects join e in employees join pe in project_employee on 条件
 where pe.id == 16
 select new 
{
e.empName
...
 };