2013-11-28 51 views
0

我有一個名爲Workbook的表,它與表「Revisorsberetning」有1對多的關係,這個表與Project是多對一的關係。 所以: 工作簿 - > Revisorsberetning - >項目LINQ雙連接語句

我只是想獲得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,這就是爲什麼你看到的項目和孤單不是的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; 
+0

如果你的意思是返回另一個值,嘗試'選擇新{u.PROJECT_NAME,u.ProjectId};' – Grundy

+0

也在SQL'dbo.Workbook.WorkbookId = 2'在linq'c.WorkbookId == 1' – Grundy

+0

@Grundy這只是一個錯字,是不是相對於我有 – RedHotScalability

回答

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;