linq sum问题
各位大虾 在vb.net中 如何用linq对某个字段求sum
------最佳解决方案--------------------Sum - Simple
This sample uses Sum to find the total freight over all Orders.
Public Sub LinqToSqlCount03()
Dim q = (From o In db.Orders _
Select o.Freight).Sum()
Console.WriteLine(q)
End Sub
Result:
64914.4400
Sum - Mapped
This sample uses Sum to find the total number of units on order over all Products.
Public Sub LinqToSqlCount04()
Dim q = (From p In db.Products _
Select CInt(p.UnitsOnOrder.Value)).Sum()
Console.WriteLine(q)
End Sub
Result:
780
http://msdn.microsoft.com/en-us/vstudio/bb737922
------其他解决方案--------------------VB.NET
Dim result = data.Sum(Function(x) x.求和的字段)
------其他解决方案--------------------var result = data.Sum(x => x.求和的字段);
------其他解决方案--------------------
给个例子给你http://msdn.microsoft.com/zh-cn/library/system.linq.enumerable.sum.aspx
------其他解决方案--------------------
这个
------其他解决方案--------------------linq的语法到哪边都一样