0

SQL を LINQ に変換する方法

SELECT 
          [good_id]
          ,MIN([good_price]) as minPrice
          ,Count([distributor_id]) as distrCount
      FROM [Provizor].[dbo].[PRICES] where region_id=22
      GROUP BY [good_id]
      ORDER BY distrCount desc 

LINQ グループ化でこれを行う方法

4

1 に答える 1

3

このようなもの:

var query = dbo.Prices
               .Where(x => x.region_id == 22)
               .GroupBy(x => x.good_id)
               .Select(g => new 
                { 
                   minPrice = g.Min(x => x.good_price), 
                   distrCount = g.Count(x=> x.distributor_id!=null)
                }
               .OrderByDescending(x => x.distrCount); 
于 2012-04-28T04:47:33.620 に答える