DataServiceRequest<TElement> Klasa

Definicja

Reprezentuje obiekty żądań przesłane jako partia do usługi danych.

generic <typename TElement>
public ref class DataServiceRequest sealed : System::Data::Services::Client::DataServiceRequest
public sealed class DataServiceRequest<TElement> : System.Data.Services.Client.DataServiceRequest
type DataServiceRequest<'Element> = class
    inherit DataServiceRequest
Public NotInheritable Class DataServiceRequest(Of TElement)
Inherits DataServiceRequest

Parametry typu

TElement
Dziedziczenie
DataServiceRequest<TElement>

Przykłady

Po ExecuteBatch powrocie cała odpowiedź HTTP dla żądania wsadowego została odczytowana ze strumienia sieciowego, ale odpowiedzi nie zostały przetworzone. Rozpoznawanie tożsamości i materializacja obiektów nie występują dla określonej jednostki w odpowiedzi, dopóki nie zostanie iteracja, jak pokazano w poniższym przykładzie.

DataServiceContext service = new DataServiceContext(new   
                                                    Uri("http://myserviceroot"));  

// Create query batches.  
DataServiceRequest[] reqs = new DataServiceRequest[] {   
    new DataServiceRequest<Category>(  
            new Uri("http://myserviceroot/Categories")),  
            new DataServiceRequest<Customer>(  
            new Uri("http://myserviceroot/Customers"))  
};  

DataServiceResponse dsr;  
try  
{  
    // Client will not throw an exception on ExecuteBatch because the   
    // entire response has not been processed yet to know  
    // whether an exception should be thrown.  

    dsr = service.ExecuteBatch(reqs);     

    if (dsr.IsBatchResponse)   
    {  
        /*inspect HTTP artifacts associated with the entire batch:  
                      dsr.BatchHeaders, dsr.BatchStatusCode*/ }  

    foreach (QueryOperationResponse qr in dsr)  
    {  
        if (IsErrorStatusCode(qr.StatusCode))     
        {  
            //q.Error.Message contains the full contents of the error.  
            /* process any part of the Error Contract (<error> element)  
                      sent from the service.  */  
            }  
        }  
        else  
        {  
            if (qr.Query.ElementType == typeof(Customer))  
            {  
                //process customers  
                foreach (Customer c in qr){ /*process the customer*/ }  

                // the DataServiceContext does not materialize, resolve  
                // identity on Customer until it is enumerated.  
            }  
            else if (qr.Query.ElementType == typeof(Category))  
            {  
                // Process categories.  
                foreach (Category cat in qr)  
                {   
                    /*process the category*/   
                 }  
                // the DataServiceContext does not materialize or  
                // resolve identity on the Category until  
                // it is enumerated.  
                // This means that instream errors will be thrown  
                // during iteration.  
            }  
        }  
    }  
}  
catch (DataServiceRequestException e)  
{  
    // This error is thrown if the data service returns with  
    // a response code < 200 or >299 or the top level element.  
    // If neither of the above or true, this exception is not   
    // thrown.  

    dsr = e.Response;  

    if (dsr.IsBatchResponse)   
    {   
        /*inspect HTTP artifacts associated with the entire batch:  
                        dsr.BatchHeaders, dsr.BatchStatusCode*/   
    }  

    /* There will always only be one of these because if the top level  
     status code was >=200 and =<299 and the first element was not an  
     error, the call to start the query will not throw. */  

    foreach (QueryOperationResponse qr in dsr)  
    {  
        if (qr.Error != null)  
        {  
            // Process error.  
        }  
    }     
}  

Uwagi

W grupie zapytań przesłanych jako partia do usługi danych zapytania są określane jako DataServiceRequest<TElement> wystąpienia. Zwracany DataServiceResponse jest element reprezentujący odpowiedź żądania wsadowego jako całości. Poszczególne odpowiedzi zapytania są reprezentowane jako QueryOperationResponse obiekty pochodzące z OperationResponseklasy , które są dostępne przez wyliczenie DataServiceResponse wystąpienia.

Konstruktory

DataServiceRequest<TElement>(Uri)

Inicjuje nowe wystąpienie klasy DataServiceRequest<TElement>.

Właściwości

ElementType

Pobiera typ obiektu użytego do utworzenia DataServiceRequest<TElement> wystąpienia.

RequestUri

Pobiera obiekt URI, który zawiera ciąg żądania.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Reprezentuje identyfikator URI zapytania w usłudze danych.

(Odziedziczone po DataServiceRequest)

Dotyczy