DataServiceQuery(Of TElement).IncludeTotalCount Method ()


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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 Function IncludeTotalCount As DataServiceQuery(Of TElement)

Return Value

Type: System.Data.Services.Client.DataServiceQuery(Of TElement)

A new DataServiceQuery(Of 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.
Dim context = New NorthwindEntities(svcUri)

' Define a new query for Customers that includes the total count.
Dim query As DataServiceQuery(Of Customer) = _

    ' Execute the query for all customers and get the response object.
    Dim response As QueryOperationResponse(Of Customer) = _
        CType(query.Execute(), QueryOperationResponse(Of 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.
    For Each customer As Customer In response
        Console.WriteLine(vbTab & "Customer Name: {0}", customer.CompanyName)
Catch ex As DataServiceQueryException
    Throw New ApplicationException( _
            "An error occurred during query execution.", ex)
End Try

.NET Framework
Available since 3.5
Available since 4.0
Return to top