How to: Page Through Query Results
This topic shows how to page the results of a query. The example gets five Product objects after skipping the first six in the query result, which is sorted by Product.UnitPrice.
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() )
{
IQueryable<Product> products = dbContext.Products.OrderBy( p => p.UnitPrice );
products = products.Skip( 6 ).Take( 5 );
foreach ( Product product in products )
{
Console.WriteLine( product.ProductName );
}
}
Using dbContext As New FluentModel()
Dim products As IQueryable(Of Product) = dbContext.Products.OrderBy(Function(p) p.UnitPrice)
products = products.Skip(6).Take(5)
For Each _product As Product In products
Console.WriteLine(_product.ProductName)
Next _product
End Using