DataServiceContext.EndExecute<TElement>(IAsyncResult) Metode
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Dipanggil untuk menyelesaikan 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)
Jenis parameter
- TElement
Jenis yang dikembalikan oleh kueri.
Parameter
- asyncResult
- IAsyncResult
IAsyncResult Objek.
Mengembalikan
Hasil yang dikembalikan oleh operasi kueri.
Pengecualian
Kapan asyncResult
adalah null
.
Kapan asyncResult
tidak berasal dari instans ini DataServiceContext .
-atau-
Metode EndExecute<TElement>(IAsyncResult) ini sebelumnya dipanggil.
Ketika kesalahan dimunculkan baik selama eksekusi permintaan atau ketika mengonversi konten pesan respons menjadi objek.
Contoh
Contoh berikut menunjukkan cara menjalankan kueri asinkron dengan memanggil BeginExecute metode untuk memulai kueri. Delegasi sebaris memanggil EndExecute metode untuk menampilkan hasil kueri. Contoh ini menggunakan DataServiceContext yang dihasilkan oleh alat Tambahkan Referensi Layanan berdasarkan layanan data Northwind, yang dibuat saat Anda menyelesaikan Layanan Data WCF .
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
Keterangan
Menurut pola asinkron awal standar, panggilan balik yang disediakan dipanggil saat hasil kueri diambil. Untuk informasi selengkapnya, lihat Operasi Asinkron.
Ketika panggilan balik dipanggil, semua hasil telah dibaca dari aliran HTTP, tetapi belum diproses; tidak ada objek lokal yang menghadap pengguna yang telah terwujud atau dimodifikasi dan resolusi identitas belum terjadi. Ketika EndExecute dipanggil, DataServiceResponse dibuat dan dikembalikan tetapi hasilnya masih belum diproses. Resolusi identitas, materialisasi objek, dan manipulasi hanya terjadi ketika pengguna menghitung hasilnya.
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk