Share via


DataServiceQueryContinuation<T> 类

封装返回已分页的 WCF 数据服务 查询结果的下一页的 URI。 

继承层次结构

System.Object
  System.Data.Services.Client.DataServiceQueryContinuation
    System.Data.Services.Client.DataServiceQueryContinuation<T>

命名空间:  System.Data.Services.Client
程序集:  Microsoft.Data.Services.Client(在 Microsoft.Data.Services.Client.dll 中)

语法

声明
Public NotInheritable Class DataServiceQueryContinuation(Of T) _
    Inherits DataServiceQueryContinuation
用法
Dim instance As DataServiceQueryContinuation(Of T)
public sealed class DataServiceQueryContinuation<T> : DataServiceQueryContinuation
generic<typename T>
public ref class DataServiceQueryContinuation sealed : public DataServiceQueryContinuation
[<SealedAttribute>]
type DataServiceQueryContinuation<'T> =  
    class
        inherit DataServiceQueryContinuation
    end
JScript 不支持一般类型和方法。

类型参数

  • T
    延续令牌的类型。

DataServiceQueryContinuation<T> 类型公开以下成员。

属性

  名称 说明
公共属性 NextLinkUri 获取用于从已分页的查询结果返回数据的下一页的 URI。 (从 DataServiceQueryContinuation 继承。)

页首

方法

  名称 说明
公共方法 Equals (从 Object 继承。)
受保护方法 Finalize (从 Object 继承。)
公共方法 GetHashCode (从 Object 继承。)
公共方法 GetType (从 Object 继承。)
受保护方法 MemberwiseClone (从 Object 继承。)
公共方法 ToString 以字符串形式返回下一个链接 URI。 (从 DataServiceQueryContinuation 继承。)

页首

示例

下面的示例使用 do…while 循环从数据服务的分页结果中加载 Customers 实体。

' Create the DataServiceContext using the service URI.
Dim context = New NorthwindEntities(svcUri)
Dim token As DataServiceQueryContinuation(Of Customer) = Nothing
Dim pageCount = 0

Try
    ' Execute the query for all customers and get the response object.
    Dim response As QueryOperationResponse(Of Customer) = _
        CType(context.Customers.Execute(), QueryOperationResponse(Of Customer))

    ' With a paged response from the service, use a do...while loop 
    ' to enumerate the results before getting the next link.
    Do
        ' Write the page number.
        Console.WriteLine("Page {0}:", pageCount + 1)

        ' If nextLink is not null, then there is a new page to load.
        If token IsNot Nothing Then
            ' Load the new page from the next link URI.
            response = CType(context.Execute(Of Customer)(token),  _
            QueryOperationResponse(Of Customer))
        End If

        ' Enumerate the customers in the response.
        For Each customer As Customer In response
            Console.WriteLine(vbTab & "Customer Name: {0}", customer.CompanyName)
        Next

        ' Get the next link, and continue while there is a next link.
        token = response.GetContinuation()
    Loop While token IsNot Nothing
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);
DataServiceQueryContinuation<Customer> token = null;
int pageCount = 0; 

try
{ 
    // Execute the query for all customers and get the response object.
    QueryOperationResponse<Customer> response =
        context.Customers.Execute() as QueryOperationResponse<Customer>;

    // With a paged response from the service, use a do...while loop 
    // to enumerate the results before getting the next link.
    do
    {
        // Write the page number.
        Console.WriteLine("Page {0}:", pageCount++);

        // If nextLink is not null, then there is a new page to load.
        if (token != null)
        {
            // Load the new page from the next link URI.
            response = context.Execute<Customer>(token)
                as QueryOperationResponse<Customer>;
        }

        // Enumerate the customers in the response.
        foreach (Customer customer in response)
        {
            Console.WriteLine("\tCustomer Name: {0}", customer.CompanyName);
        }
    }

    // Get the next link, and continue while there is a next link.
    while ((token = response.GetContinuation()) != null);
}
catch (DataServiceQueryException ex)
{
    throw new ApplicationException(
        "An error occurred during query execution.", ex);
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。

请参阅

参考

System.Data.Services.Client 命名空间

其他资源

加载延迟的内容(WCF 数据服务)