2012-02-13 51 views
2

任何人都可以幫助我轉換一些SQL查詢惠特權加入這樣的LINQ?SQL到LINQ:RIGHT JOIN在LINQ

SELECT dbo.FinnTrans.SanadID, dbo.FinnTrans.Date, dbo.FinnAccount.ID AS AccID, 
dbo.FinnAccount.FullId, dbo.FinnAccount.Name, SUM(dbo.FinnTrans.Debit) AS TotalDebit, 
SUM(dbo.FinnTrans.Credit) AS TotalCredit 
FROM dbo.FinnAccount AS FinnAccount_1 LEFT OUTER JOIN 
dbo.FinnAccount ON FinnAccount_1.ParentId = dbo.FinnAccount.ID RIGHT OUTER JOIN 
dbo.FinnTrans LEFT OUTER JOIN 
dbo.FinnAccount AS FinnAccount_2 ON dbo.FinnTrans.AccID = FinnAccount_2.ID ON 
FinnAccount_1.ID = FinnAccount_2.ParentId 
WHERE (dbo.FinnTrans.FPID = 7) AND (FinnAccount_2.AccLevel = 3) 
GROUP BY dbo.FinnTrans.SanadID, dbo.FinnTrans.Date, dbo.FinnAccount.ID, 
dbo.FinnAccount.Name, dbo.FinnAccount.FullId 
HAVING (dbo.FinnTrans.SanadID = 1) 
+0

http://stackoverflow.com/questions/2730810/right-outer-join-in-linq – adontz 2012-02-13 11:35:55

+0

無效TSQL,沒有連接條件的權利了加盟。 – Jodrell 2012-02-13 14:18:45

+0

和2表示下一個左外側 – Jodrell 2012-02-13 14:20:52

回答

1

我冒昧地爲你的TSQL做了一點小事。

最後兩個連接條件對我來說顯得格格不入,所以這個TSQL不能被解析。

SELECT 
        [t].SanadID 
       , [t].Date 
       , [a].ID [AccID] 
       , [a].FullId 
       , [a].Name 
       , SUM([t].Debit) [TotalDebit] 
       , SUM([t].Credit) [TotalCredit] 
    FROM 
       dbo.FinnAccount [a1] 
     LEFT OUTER JOIN 
       dbo.FinnAccount [a] 
        ON [a1].ParentId = [a].ID 
     RIGHT OUTER JOIN 
       dbo.FinnTrans [t] 
     LEFT OUTER JOIN 
       dbo.FinnAccount [a2] 
        ON [a].AccID = [a2].ID 
        ON [a1].ID = [a2].ParentId 
    WHERE 
       [t].FPID = 7 
     AND 
       [a2].AccLevel = 3 
    GROUP BY 
        [t].SanadID 
       , [t].Date 
       , [a].ID 
       , [a].Name 
       , [a].FullId 
     HAVING 
       [t].SanadID = 1