0

必要に応じて、LINQ ラムダ式またはクエリ構文でこのクエリを作成するにはどうすればよいですか? 私はしばらくの間試してきました。複数の結合が難しくなっています。結合の合計レコードは 2000 を超え、最終結果は約 15 レコードになるはずです

select 
    year([date]), 
    month([date]),
    sum(ot.rate)
from s as s 
join cs cs on cs.s_id= s.id
join ot ot on ot.id = cs.o_id
group by
    year([date]), 
    month([date])

これは私が持っている最も近いものですが、コンパイルされません。select ブロック内から ot プロパティにアクセスできません。

    var query = from se in table_se
        join cs in table_cs on se.Id equals cs.S_Id
        join ot in table_ot on cs.O_Id equals ot.Id
        group se by new { se.Date.Year, se.Date.Month } into grp 
        select new
        {
            grp.Key.Year,
            grp.Key.Month,
            grp.Sum(ot.Rate)
        };
4

1 に答える 1

5

あなたはとても近かっEnumerable.Sumた - 述語を取る

var query = from se in table_se
        join cs in table_cs on se.Id equals cs.S_Id
        join ot in table_ot on cs.O_Id equals ot.Id
        group ot by new { se.Date.Year, se.Date.Month } into grp 
        select new
        {
            Year = grp.Key.Year,
            Month = grp.Key.Month,
            Sum = grp.Sum(x => x.Rate)
        };
于 2013-09-12T12:41:35.790 に答える