以下の論理形式のデータをクラスに格納する必要があります。
"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