如何在此linq查询中添加orderby函数。我想通过计算投票显示行顺序(您可以在选择查询中看到计算)
(from e in db.FoodItems
join o in db.Ratings
on e.itemid equals o.itemid into g
select new FoodView
{ itemid=e.itemid,
caption=e.caption,
description=e.description,
price=e.price,
pubdate=e.pubdate,
imageurl=e.imageurl,
videourl=e.videourl,
itemname = e.itemname,
vote = (long)Math.Round((double)(g.Sum(x => (int?)x.vote) ?? 0) / g.Count(),0)
}).Take(8).ToList();
答案 0 :(得分:3)
.OrderBy(x => x.vote).Take(8).ToList()
答案 1 :(得分:0)
您可以在拍摄后添加吗?
(from e in db.FoodItems
join o in db.Ratings
on e.itemid equals o.itemid into g
select new FoodView
{ itemid=e.itemid,
caption=e.caption,
description=e.description,
price=e.price,
pubdate=e.pubdate,
imageurl=e.imageurl,
videourl=e.videourl,
itemname = e.itemname,
vote = (long)Math.Round((double)(g.Sum(x => (int?)x.vote) ?? 0) / g.Count(),0)
}).OrderBy(f => f.vote).Take(8).ToList();
答案 2 :(得分:0)
你可以......
.Take(8).ToList().OrderBy(item => item.vote);