DataServiceQuery<TElement>.IncludeTotalCount Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Begär att antalet alla entiteter i entitetsuppsättningen returneras infogat med frågeresultatet.
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)
Returer
Ett nytt DataServiceQuery<TElement> objekt som har inline count-alternativet inställt.
Exempel
Det här exemplet kör en fråga när den IncludeTotalCount anropar metoden. Egenskapen TotalCount används för att fastställa antalet entiteter som returneras av frågan.
// 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
Kommentarer
IncludeTotalCount Att anropa metoden motsvarar att inkludera frågealternativet $inlinecount i fråge-URI:n.