DataServiceContext.Execute Metoda

Definicja

Wysyła żądanie do usługi danych w celu wykonania określonego identyfikatora URI.

Przeciążenia

Execute<T>(DataServiceQueryContinuation<T>)

Wysyła żądanie do usługi danych w celu pobrania następnej strony danych w wynikach zapytania stronicowanego.

Execute<TElement>(Uri)

Wysyła żądanie do usługi danych w celu wykonania określonego identyfikatora URI.

Execute<T>(DataServiceQueryContinuation<T>)

Wysyła żądanie do usługi danych w celu pobrania następnej strony danych w wynikach zapytania stronicowanego.

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)

Parametry typu

T

Typ zwracany przez zapytanie.

Parametry

continuation
DataServiceQueryContinuation<T>

DataServiceQueryContinuation<T> Obiekt reprezentujący następną stronę danych do zwrócenia z usługi danych.

Zwraca

Odpowiedź zawierająca następną stronę danych w wyniku zapytania.

Wyjątki

Gdy podczas wykonywania żądania zostanie zgłoszony błąd lub gdy konwertuje zawartość komunikatu odpowiedzi na obiekty.

Uwagi

Podany DataServiceQueryContinuation<T> obiekt zawiera identyfikator URI, który po wykonaniu zwraca następną stronę danych w wyniku zapytania.

Dotyczy

Execute<TElement>(Uri)

Wysyła żądanie do usługi danych w celu wykonania określonego identyfikatora 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)

Parametry typu

TElement

Typ zwracany przez zapytanie.

Parametry

requestUri
Uri

Identyfikator URI, do którego zostanie wysłane żądanie zapytania. Identyfikator URI może być dowolnym prawidłowym identyfikatorem URI usługi danych. Może zawierać parametry zapytania $.

Zwraca

IEnumerable<TElement>

Wyniki operacji zapytania.

Wyjątki

Gdy odpowiedź nie zostanie odebrana z żądania do .requestUri

Gdy requestUri wartość to null.

Jeśli requestUri nie jest prawidłowym identyfikatorem URI dla usługi danych.

Gdy podczas wykonywania żądania zostanie zgłoszony błąd lub gdy konwertuje zawartość komunikatu odpowiedzi na obiekty.

Usługa danych zwraca błąd HTTP 404: Nie znaleziono zasobu.

Przykłady

W tym przykładzie użyto do…while pętli do ładowania Customers jednostek ze stronicowanych wyników z usługi danych. Metoda jest wywoływana Execute przy użyciu następnego identyfikatora URI linku w celu odbierania następnej strony danych.

// 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

Uwagi

Metoda Execute jest używana do wykonywania zapytań dotyczących usługi danych według identyfikatora URI. Metoda powoduje wysłanie żądania HTTP GET do usługi danych. Określony identyfikator URI żądania może być bezwzględny lub względny.

requestUri Jeśli wartość jest bezwzględna, ta metoda sprawdza, czy identyfikator URI wskazuje tę samą usługę danych, która została określona podczas konstruowania DataServiceContext. requestUri Jeśli parametr jest względny, ta metoda usuwa wszystkie wiodące ukośniki i dołącza requestUri do elementów podanych podczas konstruowania elementu DataServiceContext. Ukośnik jest dołączany po przekazaniu identyfikatora URI do konstruktora DataServiceContext , jeśli jeszcze go nie ma.

Gdy ta metoda zwróci, cała odpowiedź HTTP dla żądania została odczytowana ze strumienia sieciowego, ale odpowiedź nie zostanie przetworzona; nie ma rozpoznawania tożsamości ani materializacji obiektów. Rozpoznawanie tożsamości i pełne materializacja obiektu nie są wykonywane dla określonej jednostki w odpowiedzi, dopóki nie zostanie wyliczone.

Zobacz też

Dotyczy