DataServiceContext.EndExecute<TElement>(IAsyncResult) Methode

Definition

Wird aufgerufen, um den BeginExecute<TElement>(Uri, AsyncCallback, Object)Vorgang abzuschließen.

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

Typparameter

TElement

Der von der Abfrage zurückgegebene Typ.

Parameter

asyncResult
IAsyncResult

IAsyncResult-Objekt

Gibt zurück

IEnumerable<TElement>

Die ergebnisse, die vom Abfragevorgang zurückgegeben werden.

Ausnahmen

Wann asyncResult ist null.

Wann asyncResult stammte nicht aus dieser DataServiceContext Instanz.

-oder-

Die EndExecute<TElement>(IAsyncResult) Methode wurde zuvor aufgerufen.

Wenn während der Ausführung der Anforderung ein Fehler ausgelöst wird oder der Inhalt der Antwortnachricht in Objekte konvertiert wird.

Beispiele

Das folgende Beispiel zeigt, wie Sie eine asynchrone Abfrage ausführen, indem Sie die BeginExecute Methode aufrufen, um die Abfrage zu starten. Der Inlinedelegat ruft die EndExecute Methode auf, um die Abfrageergebnisse anzuzeigen. In diesem Beispiel wird das DataServiceContext vom Tool "Dienstreferenz hinzufügen" basierend auf dem Northwind-Datendienst generierte Tool verwendet, das beim Abschließen der WCF Data Services erstellt wird.

public static void BeginExecuteCustomersQuery()
{
    // Create the DataServiceContext using the service URI.
    NorthwindEntities context = new NorthwindEntities(svcUri);

    // Define the query to execute asynchronously that returns
    // all customers with their respective orders.
    DataServiceQuery<Customer> query = (DataServiceQuery<Customer>)(from cust in context.Customers.Expand("Orders")
                                       where cust.CustomerID == "ALFKI"
                                       select cust);

    try
    {
        // Begin query execution, supplying a method to handle the response
        // and the original query object to maintain state in the callback.
        query.BeginExecute(OnCustomersQueryComplete, query);
    }
    catch (DataServiceQueryException ex)
    {
        throw new ApplicationException(
            "An error occurred during query execution.", ex);
    }
}

// Handle the query callback.
private static void OnCustomersQueryComplete(IAsyncResult result)
{
    // Get the original query from the result.
    DataServiceQuery<Customer> query =
        result as DataServiceQuery<Customer>;

    foreach (Customer customer in query.EndExecute(result))
    {
        Console.WriteLine("Customer Name: {0}", customer.CompanyName);
        foreach (Order order in customer.Orders)
        {
            Console.WriteLine("Order #: {0} - Freight $: {1}",
                order.OrderID, order.Freight);
        }
    }
}
Public Shared Sub BeginExecuteCustomersQuery()
    ' Create the DataServiceContext using the service URI.
    Dim context = New NorthwindEntities(svcUri)

    ' Define the delegate to callback into the process
    Dim callback As AsyncCallback = AddressOf OnCustomersQueryComplete

    ' Define the query to execute asynchronously that returns 
    ' all customers with their respective orders.
    Dim query As DataServiceQuery(Of Customer) =
    context.Customers.Expand("Orders")

    Try
        ' Begin query execution, supplying a method to handle the response
        ' and the original query object to maintain state in the callback.
        query.BeginExecute(callback, query)
    Catch ex As DataServiceQueryException
        Throw New ApplicationException(
                "An error occurred during query execution.", ex)
    End Try
End Sub
' Handle the query callback.
Private Shared Sub OnCustomersQueryComplete(ByVal result As IAsyncResult)
    ' Get the original query from the result.
    Dim query As DataServiceQuery(Of Customer) =
        CType(result.AsyncState, DataServiceQuery(Of Customer))

    ' Complete the query execution.
    For Each customer As Customer In query.EndExecute(result)
        Console.WriteLine("Customer Name: {0}", customer.CompanyName)
        For Each order As Order In customer.Orders
            Console.WriteLine("Order #: {0} - Freight $: {1}",
                    order.OrderID, order.Freight)
        Next
    Next
End Sub

Hinweise

Gemäß dem standardmäßigen asynchronen Start-End-Muster wird der bereitgestellte Rückruf aufgerufen, wenn Abfrageergebnisse abgerufen werden. Weitere Informationen finden Sie unter "Asynchrone Vorgänge".

Wenn der Rückruf aufgerufen wird, wurden alle Ergebnisse aus dem HTTP-Datenstrom gelesen, aber nicht verarbeitet. Es wurden keine lokalen benutzerbezogenen Objekte materialisiert oder geändert, und die Identitätsauflösung ist nicht aufgetreten. Wenn EndExecute sie aufgerufen wird, wird eine DataServiceResponse erstellt und zurückgegeben, aber die Ergebnisse wurden noch nicht verarbeitet. Identitätsauflösung, Objektmaterialisierung und Manipulation treten nur auf, wenn der Benutzer die Ergebnisse aufzählt.

Gilt für:

Weitere Informationen