How to: Sort Data

This topic shows how to sort query results. The example returns a collection of Product objects sorted alphabetically by the first letter of Product.ProductName.

To run the code in this example, you need to create a new Telerik Data Access Domain Model based on the Northwind database.

The following code is the LINQ example.

using ( EntitiesModel dbContext = new EntitiesModel() )
{
   var products = from product in dbContext.Products
                  orderby product.ProductName
                  select product;
   foreach ( Product product in products )
   {
       Console.WriteLine( "ProductName: {0}", product.ProductName );
   }
}
Using dbContext As New EntitiesModel()
 Dim products = From product In dbContext.Products
                Order By product.ProductName
                Select product
 For Each _product As Product In products
  Console.WriteLine("ProductName: {0}", _product.ProductName)
 Next _product
End Using

See Also