2
喜有以下查詢,我需要轉換爲LINQ(VB.net 10),我掙扎着爬分組的權利。轉換TSQL到LINQ
你怎麼稱之爲LINQ查詢有一個地方的孩子(tblApplicationAccess)和組對父表(tblBusinessUnit)結果的條款?
TSQL
SELECT tblBusinessUnit.ID, tblBusinessUnit.Name
FROM tblBusinessUnit INNER JOIN tblApplicationAccess ON
tblBusinessUnit.ID = tblApplicationAccess.BUID
WHERE(tblApplicationAccess.ApplicationID = @AppID)
GROUP BY tblBusinessUnit.ID, tblBusinessUnit.Name ORDER BY [Name]
實體模型
更新
OK,我已完成了工作,但我不知道這是否是最好 這樣做的方法。我是否需要創建顯式連接?這是否有效?
Dim var = (From bu In hf.BusinessUnits
Join app In hf.ApplicationAccesses On bu.ID Equals app.BUID
Where app.ApplicationID.Equals(56)
Group By bu.ID, bu.Name, bu.IsInternalSupplier Into Group
Select New BusinessUnitModel With {.ID = ID,
.Name = Name,
.IsInternalSupplier = IsInternalSupplier}).ToList
你使用LINQ2SQL還是EF? –
實體框架4 –
在我看來,該組是沒有必要的,你只是希望結果按名稱排序,不是嗎? – Dabblernl