windows Linq to SQL - 如何对查询结果进行排序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6009502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linq to SQL - How to sort results from query
提问by James
I have a LINQ query I am retrieving, although in its context how would I sort the output, I have tried sortby etc. but to no avail
我有一个正在检索的 LINQ 查询,尽管在其上下文中我将如何对输出进行排序,但我尝试过 sortby 等,但无济于事
DataClasses1DataContext db = new DataClasses1DataContext();
var returnall = from p in db.Orders
select p.ShipName;
回答by SirViver
var returnall = from p in db.Orders
orderby p.ShipName
select p.ShipName;
A handy reference for various LINQ functions can be found on the MSDN samples page.
可以在MSDN 示例页面上找到各种 LINQ 函数的方便参考。
回答by anishMarokey
you can use OrderByto order the single property for multiple property use ThenByalso
DataClasses1DataContext db = new DataClasses1DataContext();
var returnall = db.OrderBy(r=> r.OrderDelivaryDate).
ThenBy(r => r. OrderName);
This query will sort first by OrderDelivaryDate
then by OrderName
此查询将首先排序,OrderDelivaryDate
然后按OrderName
Here is some simple linq queries http://msdn.microsoft.com/en-us/vcsharp/aa336756#thenBySimple
这是一些简单的 linq 查询http://msdn.microsoft.com/en-us/vcsharp/aa336756#thenBySimple
回答by zellio
var ret = db.Orders.OrderBy( x => x.ShipName );