DataServiceQuery<TElement>.IncludeTotalCount Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Solicita que el recuento de todas las entidades del conjunto de entidades se devuelva alineado con los resultados de la consulta.
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)
Devoluciones
Nuevo objeto DataServiceQuery<TElement> que tiene establecida la opción de recuento alineado.
Ejemplos
En este ejemplo se ejecuta una consulta después de llamar al método IncludeTotalCount. La propiedad TotalCount se emplea para determinar el número de entidades devueltas por la consulta.
// 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
Comentarios
Llamar al IncludeTotalCount método equivale a incluir la $inlinecount
opción de consulta en el URI de consulta.