LINQ双联接语句



我有一个名为Workbook的表,它与"Revisorsberetning"表有一对多关系,后者与Project有多对一关系。因此:工作簿-->审查员培训-->项目

我只想得到一个与给定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;

尝试此变体

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;

相关内容

  • 没有找到相关文章

最新更新