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 回答