DataServiceContext.Execute Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Belirli bir URI'yi yürütmek için veri hizmetine bir istek gönderir.
Aşırı Yüklemeler
Execute<T>(DataServiceQueryContinuation<T>) |
Disk belleğine alınmış sorgu sonucundaki bir sonraki veri sayfasını almak için veri hizmetine bir istek gönderir. |
Execute<TElement>(Uri) |
Belirli bir URI'yi yürütmek için veri hizmetine bir istek gönderir. |
Execute<T>(DataServiceQueryContinuation<T>)
Disk belleğine alınmış sorgu sonucundaki bir sonraki veri sayfasını almak için veri hizmetine bir istek gönderir.
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)
Tür Parametreleri
- T
Sorgu tarafından döndürülen tür.
Parametreler
- continuation
- DataServiceQueryContinuation<T>
Veri DataServiceQueryContinuation<T> hizmetinden döndürülecek bir sonraki veri sayfasını temsil eden nesne.
Döndürülenler
Sorgu sonucundaki bir sonraki veri sayfasını içeren yanıt.
Özel durumlar
İsteğin yürütülmesi sırasında veya yanıt iletisinin içeriğini nesnelere dönüştürdüğünde bir hata oluştuğunda.
Açıklamalar
Sağlanan DataServiceQueryContinuation<T> nesne, yürütüldüğünde sorgu sonucunda bir sonraki veri sayfasını döndüren URI'yi içerir.
Şunlara uygulanır
Execute<TElement>(Uri)
Belirli bir URI'yi yürütmek için veri hizmetine bir istek gönderir.
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)
Tür Parametreleri
- TElement
Sorgunun döndürdüğü tür.
Parametreler
- requestUri
- Uri
Sorgu isteğinin gönderileceği URI. URI, geçerli bir veri hizmeti URI'si olabilir. $ sorgu parametreleri içerebilir.
Döndürülenler
Sorgu işleminin sonuçları.
Özel durumlar
bir istekten requestUri
yanıt alınmıyorsa.
olduğunda requestUri
null
.
Veri requestUri
hizmeti için geçerli bir URI olmadığında.
İsteğin yürütülmesi sırasında veya yanıt iletisinin içeriğini nesnelere dönüştürdüğünde bir hata oluştuğunda.
Veri hizmeti bir HTTP 404: Kaynak Bulunamadı hatası döndürür.
Örnekler
Bu örnekte, veri hizmetinden alınan sayfalanmış sonuçlardan varlıkları yüklemek Customers
için bir döngü kullanılırdo…while
. Yöntemi Execute , sonraki veri sayfasını almak için bir sonraki bağlantı URI'sini kullanarak çağrılır.
// 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
Açıklamalar
Execute yöntemi bir veri hizmetini URI ile sorgulamak için kullanılır; yöntemi veri hizmetine bir HTTP GET isteği verilmesine neden olur. Belirtilen istek URI'si mutlak veya göreli olabilir.
requestUri
mutlaksa, bu yöntem URI'nin oluşturulurken DataServiceContextbelirtilen veri hizmetine işaret edip etmediğini doğrular. requestUri
göreliyse, bu yöntem öndeki eğik çizgileri keser ve oluşturulurken DataServiceContextsağlanana eklerrequestUri
. URI oluşturucuya DataServiceContext geçirildikten sonra eğik çizgi eklenir ( yoksa).
Bu yöntem döndürdüğünde, istek için tüm HTTP yanıtı ağ akışından okunur, ancak yanıt işlenmez; kimlik çözümlemesi veya nesne gerçekleştirme yoktur. Yanıttaki belirtilen varlık numaralandırılana kadar kimlik çözümlemesi ve tam nesne gerçekleştirmesi gerçekleşmez.
Ayrıca bkz.
- Ertelenmiş İçeriği Yükleme (WCF Veri Hizmetleri)
- Nasıl yapılır: Sayfalanmış Sonuçları Yükleme (WCF Veri Hizmetleri)