c# - How do you get the sum of the product of two properties in an IEnumerable using LINQ? -
i have ienumerable<dynamic> sql query using dapper, , add product of 2 properties of dynamic objects in ienumerable.
i tried:
decimal total = orderdetails.aggregate((workingtotal, detail) => workingtotal + (detail.quantity * detail.unitprice)); but returns object cannot converted decimal.
i use sum instead of aggregate:
decimal total = orderdetails.sum(x => (decimal) (x.quantity * x.unitprice)); depending on situation is, can imagine potentially working without casts, or needing more casts... it's not easy tell dynamic.
Comments
Post a Comment