DataServiceRequest<TElement> 類別


表示以批次送出至資料服務的要求物件。Represents request objects submitted as a batch to the data service.

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




當傳回時 ExecuteBatch ,已從網路資料流程讀取批次要求的整個 HTTP 回應,但尚未處理回應。When ExecuteBatch returns, the entire HTTP response for the batch request has been read from the network stream, but the responses have not been processed. 回應中的指定實體直到反覆運算後才會發生識別解析和物件具體化,如下列範例所示。Identity resolution and object materialization do not occur for a specified entity in the response until it is iterated as shown in the following example.

DataServiceContext service = new DataServiceContext(new   

// 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;  
    // 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.  */  
            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.  


在以批次方式提交至資料服務的查詢群組中,查詢會指定為 DataServiceRequest<TElement> 實例。In a group of queries submitted as a batch to the data service, the queries are specified as DataServiceRequest<TElement> instances. DataServiceResponse會傳回,代表批次要求整體的回應。A DataServiceResponse is returned that represents the response of the batch request as a whole. 個別查詢回應會表示為 QueryOperationResponse 衍生自的物件,可透過 OperationResponse 列舉實例來存取 DataServiceResponseIndividual query responses are represented as QueryOperationResponse objects, derived from OperationResponse, that are accessible by enumerating the DataServiceResponse instance.



初始化 DataServiceRequest<TElement> 類別的新執行個體。Initializes a new instance of the DataServiceRequest<TElement> class.



取得用於建立 DataServiceRequest<TElement> 執行個體的物件型別。Gets the type of the object used to create the DataServiceRequest<TElement> instance.


取得包含要求字串的 URI 物件。Gets the URI object that contains the request string.



判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)

表示資料服務查詢的 URI。Represents the URI of the query to the data service.

(繼承來源 DataServiceRequest)