How can this query be transform to linq
SELECT materialId, SUM(totalAmount) as quantity FROM Inventory
It’s the sum part that I don’t know how…
query = from inv in context.Inventory
select new MaterialQuantity()
{
MaterialId = inv.materialId,
Quantity = ??
};
EDIT
Trying to sum the value of totalAmount.
It’s a view that is
materialId totalSum and other fields
1 5
1 10
1 20
So I want my linq to return me
MaterialId = 1, Quantity = 35
I’m going to give a complete guess here… assuming your inventory has multiple rows with the same materialId and you want to sum in those groups, you could use:
If you’re not trying to group though, you’ll need to clarify your question. Sample data and expected output would help.