DataServiceContext.Execute Metoda

Definice

Odešle žádost datové službě, aby spustila konkrétní identifikátor URI.

Přetížení

Name Description
Execute<T>(DataServiceQueryContinuation<T>)

Odešle žádost datové službě, která načte další stránku dat ve výsledku stránkovaného dotazu.

Execute<TElement>(Uri)

Odešle žádost datové službě, aby spustila konkrétní identifikátor URI.

Execute<T>(DataServiceQueryContinuation<T>)

Odešle žádost datové službě, která načte další stránku dat ve výsledku stránkovaného dotazu.

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 vrácený dotazem.

Parametry

continuation
DataServiceQueryContinuation<T>

Objekt DataServiceQueryContinuation<T> , který představuje další stránku dat, která se mají vrátit z datové služby.

Návraty

Odpověď, která obsahuje další stránku dat ve výsledku dotazu.

Výjimky

Při vyvolání chyby během provádění požadavku nebo při převodu obsahu zprávy odpovědi na objekty.

Poznámky

Zadaný DataServiceQueryContinuation<T> objekt obsahuje identifikátor URI, který při spuštění vrátí další stránku dat ve výsledku dotazu.

Platí pro

Execute<TElement>(Uri)

Odešle žádost datové službě, aby spustila konkrétní identifikátor 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, který dotaz vrátí.

Parametry

requestUri
Uri

Identifikátor URI, do kterého se odešle požadavek dotazu. Identifikátor URI může být libovolný platný identifikátor URI datové služby. Může obsahovat parametry dotazu $ .

Návraty

IEnumerable<TElement>

Výsledky operace dotazu.

Výjimky

Pokud odpověď není přijata z požadavku na requestUri.

Kdy requestUri je null.

Pokud requestUri není platný identifikátor URI pro datovou službu.

Při vyvolání chyby během provádění požadavku nebo při převodu obsahu zprávy odpovědi na objekty.

Datová služba vrátí chybu HTTP 404: Prostředek nebyl nalezen.

Příklady

Tento příklad používá smyčku do…while k načtení Customers entit ze stránkovaných výsledků z datové služby. Metoda Execute se volá pomocí dalšího identifikátoru URI odkazu pro příjem další stránky dat.

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

Poznámky

Metoda Execute se používá k dotazování datové služby pomocí identifikátoru URI. Metoda způsobí vydání požadavku HTTP GET pro datovou službu. Zadaný identifikátor URI požadavku může být absolutní nebo relativní.

requestUri Pokud je absolutní, tato metoda ověří, zda identifikátor URI odkazuje na stejnou datovou službu, která byla zadána při vytváření DataServiceContext. requestUri Pokud je relativní, tato metoda odstraní všechna počáteční lomítka a připojí requestUri k tomu, co bylo poskytnuto při vytváření DataServiceContext. Lomítko se připojí po předání identifikátoru URI konstruktoru DataServiceContext , pokud ještě neexistuje.

Když tato metoda vrátí, všechny odpovědi HTTP pro požadavek byly načteny ze síťového streamu, ale odpověď nebude zpracována; neexistuje žádné řešení identity ani materializace objektů. Řešení identity a úplná materializace objektů se pro zadanou entitu v odpovědi neprojeví, dokud se nevyčte.

Viz také

Platí pro