我有一个包含此信息的DataTable:
|"Repere"|"Position"|"Prix"|
|"AA" | "1" | 1800 |
|"AA" | "1" | 5200 |
|"AA" | "2" | 1500 |
|"AA" | "2" | 0300 |
|"BB" | "1" | 0010 |
“Repere”和“Position”列是String 列“Prix”为Double。
我希望在分配“Repere”和“Position”之后将“Prix”列中的值相加。
我改进使用linq来对象查询,但我不知道如何做总和。
我告诉你我的查询:
Dim ReqPrixModel = From Row In dTable_Devis.Rows _
Group Row.item("Prix") By Rep = Row.Item("Repere"), Pos = Row.item("Position") Into Group _
Select New With {.Prix = From i In dTable_Devis.Rows
Where (i.Item("Repere") = Rep And i.item("Position") = Pos)
Select (i.Item("Prix"))}
答案 0 :(得分:4)
这里有一个代码可以提供您想要的内容:
Dim ReqPrixModel = From Row In dTable_Devis _
Group DirectCast(Row, DataRow).Item("Prix") By Rep = Row.Item("Repere"), Pos = Row.Item("Position") Into grouped = Group _
Select New With {.Prix = grouped.Sum(Function(r) DirectCast(r, Double))}