This documentation is archived and is not being maintained.

DataServiceQuery<TElement>.IncludeTotalCount Method

Requests that the count of all entities in the entity set be returned inline with the query results.

Namespace:  System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)

public DataServiceQuery<TElement> IncludeTotalCount()

Return Value

Type: System.Data.Services.Client.DataServiceQuery<TElement>
A new DataServiceQuery<TElement> object that has the inline count option set.

Calling the IncludeTotalCount method is equivalent to including the $inlinecount query option in the query URI.

This example executes a query after it calls the IncludeTotalCount method. The TotalCount property is used to determine number of entities returned by the query.

// Create the DataServiceContext using the service URI.
NorthwindEntities context = new NorthwindEntities(svcUri);

// Define a new query for Customers that includes the total count.
DataServiceQuery<Customer> query = context.Customers.IncludeTotalCount();

    // Execute the query for all customers and get the response object.
    QueryOperationResponse<Customer> response = 
        query.Execute() as QueryOperationResponse<Customer>;

    // Retrieve the total count from the response.
    Console.WriteLine("There are a total of {0} customers.", response.TotalCount);

    // Enumerate the customers in the response.
    foreach (Customer customer in response)
        Console.WriteLine("\tCustomer Name: {0}", customer.CompanyName);
catch (DataServiceQueryException ex)
    throw new ApplicationException(
        "An error occurred during query execution.", ex);

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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