views:

165

answers:

1

I need a linq to entities query/ lambda expression for the following statement. Any help is greatly appreciated

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
+1  A: 

Try this:

var assetTypes = context.AssetTypes.Where(a => a.AssetClass.Id == 7).Select(a => new { a.Name, a.AssetTypeId, CountOfAssets = a.Asset.Count()).ToList();

I hope you have foreign keys in your base and model graph is created properly.

LukLed
Thanks for the solution Lukled.. The model graph has the proper associations and your solution works
samsur