如何在 LINQ 中使用 DataTable 在 vb 代码(dot.net v4.0)中执行组并对组求和?
在下面的示例中,我需要添加 group by GroupName
,ProductName
然后执行 sum on QTY
。列、顺序和位置应该保持在示例中,我只需要添加组和总和。格式应保持不变(使用 e("FieldName") 获取行)。
Dim ordersTable As DataTable = _dsProd.Tables("tblProductSummary")
Dim query =
(From e In ordersTable
Where (e("Type").ToString() = "1" Or IsDBNull(e("Type")))
Order By e("GroupSortOrder") Ascending, e("ProductName")
Select
GroupName = e("GroupName"),
ProductName = e("ProductName"),
QTY = e("QTY"),
Type= e("Type")
)