0

Id と Date でグループ化する必要がある次の構造のデータがあります。日付は配列のフィールドです。最上位の ID でグループ化された各日付の金額を合計する必要がありますが、これは linq で可能ですか?

Id 
Number 
MyArray[]

MyArray は次のとおりです。

[Amount, Date]

このようなものを使用しようとしていますが、2番目のグループ化がメインアイテムの配列にあるため機能しません

入力:

Id Number  MyArray
1    5     [{500.00,2001-03-08}, {200,2001-04-04}, {600, 2001-03-09}] 
2    6     [{700.00,2001-03-08}, {300,2001-03-08}]
1    7     [{400.00,2001-03-08}, {100, 2001-04-04}, {550.00,2001-12-12}]

期待される結果:

  Id    MyArray
   1    [{500.00+400.00,2001-03-08}, {200+100,2001-04-04}, {600, 2001-03-09}, {550.00,2001-12-12}] 
   2    [{700.00,2001-03-08}, {300,2001-03-08}]

from s in db.Schedules

group s by new {s.empid, s.weekending} into g

select new { g.Key.empid, g.Key.weekending, g.Sum(s => s.hours) };
4

1 に答える 1

-1
var results = db.Schedules.GroupBy(x => x.Id)
                          .Select(g => new
                                       {
                                           .Id = g.Key,
                                           .Data = g.SelectMany(x => x.MyArray)
                                                    .GroupBy(x => x.Date)
                                                    .Select(g2 => new { Amount = g2.Sum(x => x.Amount), Date = g2.Key })
                                                    .ToArray()
                                        });
于 2013-07-18T09:45:49.880 に答える