Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq中的求和到对象查询vb.net_Vb.net_Linq_Datatable_Linq To Objects - Fatal编程技术网

Linq中的求和到对象查询vb.net

Linq中的求和到对象查询vb.net,vb.net,linq,datatable,linq-to-objects,Vb.net,Linq,Datatable,Linq To Objects,我有一个包含以下信息的数据表: |"Repere"|"Position"|"Prix"| |"AA" | "1" | 1800 | |"AA" | "1" | 5200 | |"AA" | "2" | 1500 | |"AA" | "2" | 0300 | |"BB" | "1" | 0010 | “保留”列和“位置”列是字符串。 “Prix”列显示为双精度 我想在按“repre”和“Pos

我有一个包含以下信息的数据表:

|"Repere"|"Position"|"Prix"|  
|"AA"    | "1"      | 1800 |  
|"AA"    | "1"      | 5200 |  
|"AA"    | "2"      | 1500 |  
|"AA"    | "2"      | 0300 |  
|"BB"    | "1"      | 0010 |  
“保留”列和“位置”列是字符串。
“Prix”列显示为双精度

我想在按“repre”和“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"))}  

这里有一个代码,提供您想要的:

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))}

这里有一个代码,提供您想要的:

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))}

非常感谢你,瓦罗卡巴斯。这和我预想的完全一样。非常感谢瓦罗卡巴斯。它的工作原理完全符合我的预期。