DataServiceQuery<TElement>.IncludeTotalCount 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
请求将实体集中所有实体的计数与查询结果一起内联返回。
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> 对象。
示例
此示例在调用 IncludeTotalCount 方法之后执行查询。 TotalCount 属性用于确定查询返回的实体数量。
// 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 中包含查询选项。