![](/img/trans.png)
[英]How can I get the top three players and their high scores from a collection using linq and lambdas
[英]How do I select the top ten scores in a database table full of scores using linq in C#
我是Linq和数据库编程的新手,我真的可以使用一些帮助。
我尝试使用
var TopTen = from t in datacontext.Scores.Take(10)
orderby t.LifetimeScore descending
select t;
但这似乎只给了我数据库中的前十个条目,而不是前十个。 我知道我需要在搜索之前对表格进行排序,但我无法弄清楚。
谢谢,感谢您的帮助
您必须从结果中减去10,而不是之前:
var TopTen = (from t in datacontext.Scores
orderby t.LifetimeScore descending
select t).Take(10);
var TopTen = datacontext.Scores.OrderByDescending(t => LifetimeScore ).Take(10)
我本人是LINQ的新手,但我认为这应该可行:
var TopTen = (from t in datacontext.Scores
orderby t.LifetimeScore descending
select t).Take(10);
var TopTen = from t in datacontext.Scores
orderby t.LifetimeScore descending
select t;
TopTen = TopTen.Take(10).ToArray();
最后一条语句将确保查询已执行 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.