我正在检索一个LINQ查询,虽然在其上下文中我将如何对输出进行排序,我已经尝试过sortby等但无济于事
DataClasses1DataContext db = new DataClasses1DataContext();
var returnall = from p in db.Orders
select p.ShipName;
答案 0 :(得分:9)
var returnall = from p in db.Orders
orderby p.ShipName
select p.ShipName;
可以在MSDN samples page上找到各种LINQ函数的方便参考。
答案 1 :(得分:6)
DataClasses1DataContext db = new DataClasses1DataContext();
var returnall = db.OrderBy(r=> r.OrderDelivaryDate).
ThenBy(r => r. OrderName);
此查询将首先按OrderDelivaryDate
排序,然后按OrderName
以下是一些简单的linq查询http://msdn.microsoft.com/en-us/vcsharp/aa336756#thenBySimple
答案 2 :(得分:3)
var ret = db.Orders.OrderBy( x => x.ShipName );
答案 3 :(得分:1)