DataServiceContext.Execute Yöntem

Tanım

Belirli bir URI'yi yürütmek için veri hizmetine bir istek gönderir.

Aşırı Yüklemeler

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

Sayfalanmış sorgu sonucundaki verilerin sonraki 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>)

Sayfalanmış sorgu sonucundaki verilerin sonraki 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 sonucundaki 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 herhangi bir geçerli veri hizmeti URI'si olabilir. $ sorgu parametreleri içerebilir.

Döndürülenler

IEnumerable<TElement>

Sorgu işleminin sonuçları.

Özel durumlar

bir istekten requestUriyanıt alınmadığında.

olduğunda requestUrinull.

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 do…while için bir döngü kullanılırCustomers. yöntemi Execute , sonraki veri sayfasını almak için 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'ye göre 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 baştaki eğik çizgileri keser ve oluşturulurken requestUrisağlanana eklerDataServiceContext. URI oluşturucuya DataServiceContext geçirildikten sonra bir eğik çizgi eklenir( varsa).

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. Kimlik çözümlemesi ve tam nesne gerçekleştirme, numaralandırılana kadar yanıtta belirtilen varlık için gerçekleşmez.

Ayrıca bkz.

Şunlara uygulanır