对于以下语句,我需要LINQ to Entities查询或lambda表达式。
SELECT
at.Name,
Count(a.AssetTypeId) as CountofAssets,
at.AssetTypeId
FROM
AssetTypes at, Assets a
WHERE
at.AssetClassId = 7
GROUP BY
at.Name,at.AssetTypeID
答案 0 :(得分:3)
试试这个:
var assetTypes = context.AssetTypes.Where(a => a.AssetClass.Id == 7).Select(a => new { a.Name, a.AssetTypeId, CountOfAssets = a.Asset.Count()).ToList();
我希望您的基础中有外键,并且模型图形已正确创建。