Partilhar via


DataServiceRequest<TElement> Classe

Definição

Representa objetos de solicitação enviados como um lote para o serviço de dados.

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

Parâmetros de tipo

TElement
Herança
DataServiceRequest<TElement>

Exemplos

Quando ExecuteBatch retorna, toda a resposta HTTP para a solicitação em lote foi lida do fluxo de rede, mas as respostas não foram processadas. A resolução de identidade e a materialização do objeto não ocorrem para uma entidade especificada na resposta até que ela seja iterada, conforme mostrado no exemplo a seguir.

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

Comentários

Em um grupo de consultas enviadas como um lote para o serviço de dados, as consultas são especificadas como DataServiceRequest<TElement> instâncias. Um DataServiceResponse é retornado que representa a resposta da solicitação em lote como um todo. As respostas de consulta individuais são representadas como QueryOperationResponse objetos, derivados de OperationResponse, que são acessíveis pela enumeração da DataServiceResponse instância .

Construtores

Nome Description
DataServiceRequest<TElement>(Uri)

Inicializa uma nova instância da classe DataServiceRequest<TElement>.

Propriedades

Nome Description
ElementType

Obtém o tipo do objeto usado para criar a instância DataServiceRequest<TElement>.

RequestUri

Obtém o objeto de URI que contém a cadeia de caracteres de solicitação.

Métodos

Nome Description
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função de hash padrão.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.

(Herdado de Object)
ToString()

Representa o URI da consulta para o serviço de dados.

(Herdado de DataServiceRequest)

Aplica-se a