makak
makak

Reputation: 397

Nested select to LINQ

I have a nested group by query like this:

select min(sum_money) as minMon, max(sum_money) as maxMon from
(select sum (money) as sum_money from moneyTable where year >= 2014 group by department) as nest

and I wish to accomplish this in LINQ... ...and I am quite desperate

Upvotes: 0

Views: 65

Answers (1)

ocuenca
ocuenca

Reputation: 39376

I assume what you want is the min and max sum of money for all departments:

var nestedquery= (from m in context.MoneyTable
                  where m.year >= 2014
                  group m by m.department into g
                  select g.Sum(e=>e.money)).ToList();

var result= new { minMon= nestedquery.Min(e=>e), maxMon=nestedquery.Max(e=>e)};

Upvotes: 1

Related Questions