DataServiceContext.EndExecute<TElement>(IAsyncResult) Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Aangeroepen om de BeginExecute<TElement>(Uri, AsyncCallback, Object).
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)
Type parameters
- TElement
Het type dat door de query wordt geretourneerd.
Parameters
- asyncResult
- IAsyncResult
IAsyncResult Object.
Retouren
De resultaten die door de querybewerking worden geretourneerd.
Uitzonderingen
Wanneer asyncResult is null.
Wanneer asyncResult dit exemplaar niet afkomstig is DataServiceContext .
– of –
De EndExecute<TElement>(IAsyncResult) methode werd eerder aangeroepen.
Wanneer er een fout optreedt tijdens de uitvoering van de aanvraag of wanneer deze de inhoud van het antwoordbericht converteert naar objecten.
Voorbeelden
In het volgende voorbeeld ziet u hoe u een asynchrone query uitvoert door de BeginExecute methode aan te roepen om de query te starten. De inline gedelegeerde roept de EndExecute methode aan om de queryresultaten weer te geven. In dit voorbeeld wordt gebruikgemaakt van het DataServiceContext hulpprogramma Servicereferentie toevoegen op basis van de Northwind-gegevensservice, die wordt gemaakt wanneer u de WCF-gegevensservices voltooit.
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
Opmerkingen
Volgens het standaard asynchrone begin-endpatroon wordt de opgegeven callback aangeroepen wanneer queryresultaten worden opgehaald. Zie Asynchrone bewerkingen voor meer informatie.
Wanneer de callback wordt aangeroepen, zijn alle resultaten gelezen uit de HTTP-stream, maar zijn ze niet verwerkt; er geen lokale gebruikersgerichte objecten zijn gerealiseerd of gewijzigd en identiteitsomzetting is niet opgetreden. Wanneer EndExecute wordt aangeroepen, wordt er een DataServiceResponse gemaakt en geretourneerd, maar zijn de resultaten nog steeds niet verwerkt. Identiteitsomzetting, object materialisatie en manipulatie vinden alleen plaats wanneer de gebruiker de resultaten opsommen.