DataServiceQuery<TElement>.IncludeTotalCount Метод

Определение

Запрашивает, чтобы вместе с результатами запроса возвращалось количество всех сущностей в наборе сущностей.Requests that the count of all entities in the entity set be returned inline with the query results.

public:
 System::Data::Services::Client::DataServiceQuery<TElement> ^ IncludeTotalCount();
public System.Data.Services.Client.DataServiceQuery<TElement> IncludeTotalCount ();
member this.IncludeTotalCount : unit -> System.Data.Services.Client.DataServiceQuery<'Element>
Public Function IncludeTotalCount () As DataServiceQuery(Of TElement)

Возвращаемое значение

DataServiceQuery<TElement>

Новый объект DataServiceQuery<TElement>, в котором задан параметр возвращения количества сущностей.A new DataServiceQuery<TElement> object that has the inline count option set.

Примеры

В этом примере запрос выполняется после вызова метода IncludeTotalCount.This example executes a query after it calls the IncludeTotalCount method. Свойство TotalCount используется для определения количества сущностей, возвращаемых запросом.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();

try
{
    // 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);
}
' 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) = _
context.Customers.IncludeTotalCount()

Try
    ' 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)
    Next
Catch ex As DataServiceQueryException
    Throw New ApplicationException( _
            "An error occurred during query execution.", ex)
End Try

Комментарии

Вызов IncludeTotalCount метода эквивалентен включению $inlinecount параметра запроса в URI запроса.Calling the IncludeTotalCount method is equivalent to including the $inlinecount query option in the query URI.

Применяется к