共用方式為


DataServiceQuery<TElement>.IncludeTotalCount 方法

要求實體集中的所有實體計數以內嵌在查詢結果中的方式傳回。

命名空間:  System.Data.Services.Client
組件:  Microsoft.Data.Services.Client (在 Microsoft.Data.Services.Client.dll 中)

語法

'宣告
Public Function IncludeTotalCount As DataServiceQuery(Of TElement)
'用途
Dim instance As DataServiceQuery
Dim returnValue As DataServiceQuery(Of TElement)

returnValue = instance.IncludeTotalCount()
public DataServiceQuery<TElement> IncludeTotalCount()
public:
DataServiceQuery<TElement>^ IncludeTotalCount()
member IncludeTotalCount : unit -> DataServiceQuery<'TElement> 
public function IncludeTotalCount() : DataServiceQuery<TElement>

傳回值

型別:System.Data.Services.Client.DataServiceQuery<TElement>
已設定內嵌計數選項的新 DataServiceQuery<TElement> 物件。

備註

呼叫 IncludeTotalCount 方法等同於將 $inlinecount 查詢選項包含在查詢 URI 中。

範例

此範例會在呼叫 IncludeTotalCount 方法後執行查詢。 TotalCount 屬性是用於判斷查詢傳回的實體數目。

' 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
// 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);
}

請參閱

參考

DataServiceQuery<TElement> 類別

System.Data.Services.Client 命名空間