您好有以下查询,我需要转换为 LINQ(VB.net 10),我正在努力正确分组。
您如何将 LINQ 查询称为在子表 (tblApplicationAccess) 上有一个 where 子句并将结果分组到父表 (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]
实体模型
更新
好的,我已经让它工作了,但我不知道这是否是最好的方法。我需要创建显式连接吗?这有效率吗?
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