Share via


DataServiceContext.Execute メソッド

定義

要求をデータ サービスに送信して特定の URI を実行します。

オーバーロード

Execute<T>(DataServiceQueryContinuation<T>)

要求をデータ サービスに送信して、ページングされたクエリ結果のデータの次のページを取得します。

Execute<TElement>(Uri)

要求をデータ サービスに送信して特定の URI を実行します。

Execute<T>(DataServiceQueryContinuation<T>)

要求をデータ サービスに送信して、ページングされたクエリ結果のデータの次のページを取得します。

public:
generic <typename T>
 System::Data::Services::Client::QueryOperationResponse<T> ^ Execute(System::Data::Services::Client::DataServiceQueryContinuation<T> ^ continuation);
public System.Data.Services.Client.QueryOperationResponse<T> Execute<T> (System.Data.Services.Client.DataServiceQueryContinuation<T> continuation);
member this.Execute : System.Data.Services.Client.DataServiceQueryContinuation<'T> -> System.Data.Services.Client.QueryOperationResponse<'T>
Public Function Execute(Of T) (continuation As DataServiceQueryContinuation(Of T)) As QueryOperationResponse(Of T)

型パラメーター

T

クエリによって返される型。

パラメーター

continuation
DataServiceQueryContinuation<T>

データ サービスから返すデータの次のページを表す DataServiceQueryContinuation<T> オブジェクト。

戻り値

クエリ結果内のデータの次のページを含む応答。

例外

要求の実行中か、応答メッセージの内容をオブジェクトに変換するときにエラーが発生した場合。

注釈

指定された DataServiceQueryContinuation<T> オブジェクトには URI が含まれており、実行すると、クエリ結果のデータの次のページが返されます。

適用対象

Execute<TElement>(Uri)

要求をデータ サービスに送信して特定の URI を実行します。

public:
generic <typename TElement>
 System::Collections::Generic::IEnumerable<TElement> ^ Execute(Uri ^ requestUri);
public System.Collections.Generic.IEnumerable<TElement> Execute<TElement> (Uri requestUri);
member this.Execute : Uri -> seq<'Element>
Public Function Execute(Of TElement) (requestUri As Uri) As IEnumerable(Of TElement)

型パラメーター

TElement

クエリが返す型。

パラメーター

requestUri
Uri

クエリ要求が送信される URI。 この URI には有効なデータ サービス URI を指定できます。 $ クエリ パラメーターを含めることができます。

戻り値

IEnumerable<TElement>

クエリ操作の結果。

例外

requestUri への要求から応答が受信されなかった場合。

requestUrinull の場合。

requestUri がデータ サービスに有効な URI ではない場合。

要求の実行中か、応答メッセージの内容をオブジェクトに変換するときにエラーが発生した場合。

データ サービスから HTTP 404: Resource Not Found エラーが返されます。

次の例は、do…while ループを使用して、データ サービスからのページングされた結果の Customers エンティティを読み込みます。 Execute メソッドは、次のページのデータを受信するために次のリンク URI を使用して呼び出さます。

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

注釈

Execute メソッドを使用して URI でデータ サービスをクエリします。このメソッドにより、データ サービスに対して HTTP GET 要求が発行されます。 指定される要求 URI は、絶対 URI にも相対 URI にもすることができます。

requestUri が絶対 URI の場合、このメソッドは、その URI が DataServiceContext の作成時に指定されたのと同じデータ サービスを指すかどうかを検証します。 requestUri が相対 URI である場合、このメソッドは、先頭のスラッシュを削除し、requestUri の作成時に指定された文字列に DataServiceContext を追加します。 スラッシュは、DataServiceContext コンストラクターに渡された URI の後に追加されます (スラッシュがない場合)。

このメソッドから制御が戻った時点で、要求に対するすべての HTTP 応答がネットワーク ストリームから読み取られていますが、応答は処理されていません。また、ID 解決やオブジェクトの具体化も行われません。 列挙されるまで、応答内の特定のエンティティに対する ID 解決や完全なオブジェクトの具体化は行われません。

こちらもご覧ください

適用対象