1

我有以下查询,我想将其转换为 LINQ to SQL (c#),但我遇到了困难。

select title, barcode, count (*) as pop_rank
from favourites
group by barcode, title
order by pop_rank desc

我做到了

DataContext db = new DataContext();

using (db)
{
var test = from t in db.favourites
           group t by new 
           {
              t.barcode,
              t.title
           };
}

我正在努力按功能添加计数和顺序。

谢谢

4

1 回答 1

1

尝试:

DataContext db = new DataContext();

using (db)
{
 var test = 
          ( 
           from t in db.favourites
           group t by new 
           {
              t.barcode,
              t.title
            } into g 
             select new {g.Key.barcode, g.Key.title, pop_rank=g.Count()}
            ).OrderBy(a => a.pop_rank);
}
于 2012-12-10T03:23:11.650 回答