You can use LINQ for objects and use LINQ to calculate totals:
decimal sumLineTotal = (from od in orderdetailscollection select od.LineTotal).Sum();
You can also use lambda expressions for this, which is a bit cleaner.
decimal sumLineTotal = orderdetailscollection.Sum(od => od.LineTotal);
Then you can connect this to your Order class if you want:
Public Partial Class Order { ... Public Decimal LineTotal { get { return orderdetailscollection.Sum(od => od.LineTotal); } } }
Espo Sep 15 '08 at 5:02 2008-09-15 05:02
source share