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: 리소스를 찾을 수 없음 오류를 반환합니다.

예제

이 예제에서는 루프를 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. URI가 생성자에 전달된 후 슬래시가 DataServiceContext 추가됩니다(아직 없는 경우).

이 메서드가 반환되면 요청에 대한 모든 HTTP 응답이 네트워크 스트림에서 읽혀졌지만 응답은 처리되지 않습니다. ID 확인 또는 개체 구체화가 없습니다. ID 확인 및 전체 개체 구체화는 열거될 때까지 응답에서 지정된 엔터티에 대해 발생하지 않습니다.

추가 정보

적용 대상