Data Access has been discontinued. Please refer to this page for more information.

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 a fluent model based on the Northwind database.

The following code is the LINQ example.

using ( FluentModel dbContext = new FluentModel() )
{
   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 FluentModel()
 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