Export (0) Print
Expand All

ObjectQuery<T>.Skip Method

Orders the query results by the specified criteria and skips a specified number of results.

Namespace:  System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

public ObjectQuery<T> Skip(
	string keys,
	string count,
	params ObjectParameter[] parameters
)

Parameters

keys
Type: System.String

The key columns by which to order the results.

count
Type: System.String

The number of results to skip. This must be either a constant or a parameter reference.

parameters
Type: System.Data.Objects.ObjectParameter[]

An optional set of query parameters that should be in scope when parsing.

Return Value

Type: System.Data.Objects.ObjectQuery<T>
A new ObjectQuery<T> instance that is equivalent to the original instance with both ORDER BY and SKIP applied.

ExceptionCondition
ArgumentNullException

Any argument is null.

ArgumentException

keys is an empty string.

-or-

count is an empty string.

The Skip method cannot be used after the Top method. When you use Top after Skip, it functions like the LIMIT statement of an ORDER BY clause.

This example gets five Product objects after skipping the first three in the query result, sorted by Product.ListPrice.

using (AdventureWorksEntities advWorksContext =
    new AdventureWorksEntities())
{
    // Define the parameters used to define the "page" of returned data.
    int skipValue = 3;
    int limitValue = 5;

    try
    {
        // Define a query that returns a "page" or the full 
        // Product data using the Skip and Top methods.  
        // When Top() follows Skip(), it acts like the LIMIT statement.
        ObjectQuery<Product> query = advWorksContext.Product
            .Skip("it.ListPrice","@skip", 
                    new ObjectParameter("skip", skipValue))
            .Top("@limit", new ObjectParameter("limit", limitValue));

        // Iterate through the page of Product items. 
        foreach (Product result in query)
            Console.WriteLine("ID: {0}; Name: {1}",
            result.ProductID, result.Name);
    }
    catch (EntitySqlException ex)
    {
        Console.WriteLine(ex.ToString());
    }
}

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1

Community Additions

ADD
Show:
© 2014 Microsoft