从两个表中获取数据

时间:2011-06-09 09:49:43

标签: linq

我的数据库中有两个表:

Employee(EmployeeID, EmployeeName, EmployeeGroup)
Group(GroupID, GroupName, GroupLeader)

EmployeeGroup对应GroupID
GroupLeader对应于EmployeeID

我想选择列:

EmpoyeeID, EmployeeName, LeaderName(Customer name)

我该怎么做?

1 个答案:

答案 0 :(得分:0)

 var list = dataModel.Employee.Join( dataModel.Group, 
  e => e.EmployeeGroup, 
  g => g.GroupID, 
  (e, g) =>  
        new                                                                                         
              {
                 EmpoyeeID= e.EmpoyeeID, 
                 EmployyeName= e.EmployyeName, 
                LeaderName= g.GroupLeader.EmployyeName                
});