Linq to SQL - How to sort results from query Linq to SQL - How to sort results from query sql-server sql-server

Linq to SQL - How to sort results from query


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.


you can use OrderBy to order the single property for multiple property use ThenBy also

 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

Here is some simple linq queries http://msdn.microsoft.com/en-us/vcsharp/aa336756#thenBySimple


var ret = db.Orders.OrderBy( x => x.ShipName );