我们需要将以下逻辑形式的数据存储到一个类中:
"description 1", "activity A", "service A", Month 1 cost, month 2 cost, month 3 cost etc....
所以我有一个类对象,如下所示:
Public Class EntityTableRow
Public Description As String
Public Activity As String
Public M1 as Double
Public M2 as Double
.....
End Class
M... 属性将根据源数据(excel 数据源)中的月份数来持有每月成本。从逻辑上讲,上述类将保存类似于上述逻辑形式的数据
现在我需要根据相同的列对行进行分组,并汇总每月的成本。
为此,我正在尝试使用以下 Linq 查询:
Dim a As New List(Of EntityTableRow)
a = myTable1.TableRows
Dim lFinal2 = From el In a Group el By Key = New With {Key el.Description, Key el.Activity} Into Group _
Select New With {.Activity = Key.Description, _
.Country = Key.Activity, _
.M1 = Group.Sum(Function(x) x.M1), _
.M2 = Group.Sum(Function(x) x.M2)}
这似乎工作正常,现在我该如何更改上面的 Linq 查询,对于下面的修改类,我需要将月份成本存储在字典中,并且仍然得到分组的行,并在不同的月份列上求和?
Public Class EntityTableRow
Public Description As String
Public Activity As String
Public MonthCosts As New Dictionary(Of Integer, Double)
End Class