當前位置:成語大全網 - 新華字典 - SQL語句轉化為Linq語句

SQL語句轉化為Linq語句

分少點!回頭幫我的團隊打工償還吧!O(∩_∩)O哈哈~

-------------

我的表是Table_1s和Table_2s

linq 查詢如下:

from t in Table_1s

join f in Table_2s on t.B equals f.Key into FD

from f in FD.Where(b=>b.RowName=="B").DefaultIfEmpty()

join s in Table_2s on t.C equals s.Key into FDS

from s in FDS.Where(b=>b.RowName=="C").DefaultIfEmpty()

select new

{

A=t.A,

B=f.Value,

C=s.Value

}

---

對應sql如下:

-- Region Parameters

DECLARE @p0 NVarChar(1) SET @p0 = 'B'

DECLARE @p1 NVarChar(1) SET @p1 = 'C'

-- EndRegion

SELECT [t0].[A], [t1].[value] AS [B], [t2].[value] AS [C]

FROM [Table_1] AS [t0]

LEFT OUTER JOIN [Table_2] AS [t1] ON ([t1].[RowName] = @p0) AND ([t0].[B] = [t1].[key])

LEFT OUTER JOIN [Table_2] AS [t2] ON ([t2].[RowName] = @p1) AND ([t0].[C] = [t2].[key])

---

應該滿足妳的要求!