Share via


DataServiceRequest<TElement> Třída

Definice

Představuje objekty požadavku odeslané jako dávka do datové služby.

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
Dědičnost
DataServiceRequest<TElement>

Příklady

Při ExecuteBatch vrácení se celá odpověď HTTP pro dávkový požadavek načetla ze síťového streamu, ale odpovědi nebyly zpracovány. K překladu identity a materializaci objektů nedojde u zadané entity v odpovědi, dokud se iteruje, jak je znázorněno v následujícím příkladu.

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.  
        }  
    }     
}  

Poznámky

Ve skupině dotazů odeslaných jako dávka do datové služby se dotazy zadají jako DataServiceRequest<TElement> instance. Vrátí DataServiceResponse se odpověď, která představuje odpověď dávkového požadavku jako celku. Jednotlivé odpovědi na dotazy jsou reprezentovány jako QueryOperationResponse objekty odvozené z OperationResponse, které jsou přístupné výčtem DataServiceResponse instance.

Konstruktory

DataServiceRequest<TElement>(Uri)

Inicializuje novou instanci DataServiceRequest<TElement> třídy.

Vlastnosti

ElementType

Získá typ objektu použitého k vytvoření DataServiceRequest<TElement> instance.

RequestUri

Získá objekt URI, který obsahuje řetězec požadavku.

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Představuje identifikátor URI dotazu pro datovou službu.

(Zděděno od DataServiceRequest)

Platí pro