DataServiceContext.Execute メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
特定の 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 を指定できます。 $ クエリ パラメーターを含めることができます。
返品
クエリ操作の結果。
例外
requestUriへの要求から応答が受信されない場合。
requestUriがnullされたとき。
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 は、絶対または相対にすることができます。
requestUriが絶対である場合、このメソッドは、URI がDataServiceContextの作成時に指定されたのと同じデータ サービスを指しているかどうかを検証します。
requestUriが相対値の場合、このメソッドは先頭のスラッシュを取り除き、DataServiceContextの作成時に指定されたものにrequestUriを追加します。
DataServiceContext コンストラクターに渡された URI の後にスラッシュが追加されます (まだ存在しない場合)。
このメソッドが返されると、要求のすべての HTTP 応答がネットワーク ストリームから読み取られますが、応答は処理されていません。ID の解決やオブジェクトの具体化はありません。 ID 解決と完全なオブジェクトの具体化は、列挙されるまで、応答内の指定されたエンティティに対しては発生しません。