row_number 在linq中如何写
SELECT *
FROM
(
SELECT ROW_NUMBER() OVER(PARTITION BY cid ORDER BY price DESC) as rid,*
FROM table
) AS T
WHERE rid<=3
请把上面的sql语句写成 linq 如何写?
谢谢
------解决方案--------------------try
var ary = from t in dc.Class1 group t by t.cid into g select new { key = g.Key, source = g.OrderByDescending(tt => tt.price).Take(3) };
------解决方案--------------------var query= db.TableA.OrderByDescending(x=>x.price)
.Select((x,index)=>new{rid=index+1,x})
.Where(s=>s.rid<=3);
------解决方案--------------------
int index = 0;
List<table3> result = db.table3.OrderByDescending(c => c.out_money).ToList();
var query = from u in result
group u by u.bill_no into temp
from n in temp
orderby n.bill_no
select new
{
RowNo=index++,