2012-02-13 17 views
2

誰かが私にこのようなlinqにいくつかのSQLクエリの副産物の右の結合を変換するのを助けることができますか?SQLからLinqへ:右のジョインで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

+0

、何も出て参加権利のための条件を参加はありません。 – Jodrell

+0

と2の次の左外側 – Jodrell

答えて

1

私はあなたのTSQLを少しでも堪能できる自由を取っています。

この2つの結合条件は私に間違っているように見えるので、この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