Esp*_*spo 157
您可以执行LINQ to Objects并使用LINQ来计算总数:
decimal sumLineTotal = (from od in orderdetailscollection
select od.LineTotal).Sum();
Run Code Online (Sandbox Code Playgroud)
你也可以使用lambda表达式来做这件事,这有点"干净".
decimal sumLineTotal = orderdetailscollection.Sum(od => od.LineTotal);
Run Code Online (Sandbox Code Playgroud)
如果您愿意,可以将此连接到您的Order-class,如果您需要:
Public Partial Class Order {
...
Public Decimal LineTotal {
get {
return orderdetailscollection.Sum(od => od.LineTotal);
}
}
}
Run Code Online (Sandbox Code Playgroud)