我有以下查询,我想转换为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
};
}
我正在努力通过功能添加计数和订单。
由于
答案 0 :(得分: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);
}