How to perform correctly “group by” in linq on DataTable inside vb code?

后端 未结 2 1131
清酒与你
清酒与你 2021-01-14 20:58

Why isn\'t the following group by clause working? The original question was how do I perform group in LINQ inside vb code (dot.net v4.0) with DataTable and sum on the group?

2条回答
  •  抹茶落季
    2021-01-14 21:15

    Dim testQuery =
                     (From e In table
                      Group e By Key = New With {.GroupName = e("GroupName")}.GroupName,
                                       New With {.ProductName = e("ProductName")}.ProductName Into Group
                  Select New With {
                    .ProductName = ProductName,
                    .QTY = Group.Sum(Function(x) Convert.ToInt32(x("QTY"))),
                    .GroupName = Key.ToString
                 })
    

提交回复
热议问题