LINQ双连接语句

时间:2013-11-28 14:33:49

标签: linq sql-to-linq-conversion

我有一个名为Workbook的表,它与表“Revisorsberetning”有1对多的关系,这与Project有多对一的关系。 所以: 工作簿 - > Revisorsberetning - >项目

我只想获得一个与给定WorkbookId

的工作簿相关的项目列表

我尝试将以下SQL(SQL工作)转换为LINQ,但没有运气:

select Project.PROJECT_NAME
from Project
inner join dbo.Revisorsberetning
on dbo.Revisorsberetning.Project_ProjectId = dbo.Project.ProjectId
inner join dbo.Workbook
on dbo.Workbook.WorkbookId = 2

这是LINQ(LinqPAD,这就是为什么你看到projectS而不是dbcontext)查询似乎无法正常工作:

var sss = from u in Projects
join uc in Revisorsberetnings on u.ProjectId equals uc.Project.ProjectId
join c in Workbooks on uc.Workbook.WorkbookId  equals c.WorkbookId
where c.WorkbookId == 2
select u.PROJECT_NAME;

1 个答案:

答案 0 :(得分:0)

尝试此变体

var sss = from u in Projects
          join uc in Revisorsberetnings on u.ProjectId equals uc.Project.ProjectId
          from c in Workbooks
          where c.WorkbookId == 2
          select u.PROJECT_NAME;