共用方式為


ChangeOperationResponse 類別

定義

在列舉 SaveChanges() 類別傳回的作業回應時,於 DataServiceResponse 呼叫後傳回的結果。

public ref class ChangeOperationResponse sealed : System::Data::Services::Client::OperationResponse
public sealed class ChangeOperationResponse : System.Data.Services.Client.OperationResponse
type ChangeOperationResponse = class
    inherit OperationResponse
Public NotInheritable Class ChangeOperationResponse
Inherits OperationResponse
繼承
ChangeOperationResponse

範例

下列程式代碼示範如何處理呼叫 SaveChanges的結果。

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

// Do insert, update, delete, or attach operations.  

DataServiceResponse dsr;  

try  
{  
    dsr = service.SaveChanges(SaveChangesOptions.Batch);    
   // Or service.SaveChanges(SaveChangesOptions.ContinueOnError);   
   //Or service.SaveChanges();  
   // If there are no errors during save changes, process the results:  

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

    foreach (ChangeOperationResponse cor in dsr)  
    {  

            if (cor.Descriptor is EntityDescriptor)  
            {  
                EntityDescriptor ed = (EntityDescriptor)cor.Descriptor;  
                // This should be the case if  
                // SaveChanges did not throw an exception.    

                // After an entity is processed by SaveChanges,  
                // it is always moved to the unchanged state.  
                System.Diagnostics.Debug.Assert(  
                           ed.State == EntityStates.Unchanged);    
                // This shows that the state should be unchanged if  
                // the result is success.  

                //process the entity in the response payload: ed.Entity  
            }  
            else if (cor.Descriptor is LinkDescriptor)  
            {  
                LinkDescriptor ld = (LinkDescriptor)cor.Descriptor;  
               // This should be the case if SaveChanges did not throw an exception.  

               // After an entity is processed by SaveChanges it  
               // is always moved to the unchanged state.  
                System.Diagnostics.Debug.Assert(  
                            ld.State == EntityStates.Unchanged);    
                // The state should be unchanged if the result is success.  

                //process the link in the response payload: ld.Source,  
                // ld.SourceProperty, or ld.Target.  
            }  
     }  

}  
catch (DataServiceSaveException se)  
{  
    // Error while saving changes  
    dsr = se.Response;  

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

    foreach (ChangeOperationResponse cor in dsr)  
    {  
        if (cor.Error != null)  
        {  
            //process error  
        }  
        else  
        {  
            // same success case processing as in the loop over DSRs results in   
            // the try block. You could put that processing in a method   
            // and call it from here.      
        }  
    }  

}  

 catch(Exception)  
 {  
    // Error while saving changes, but not thrown by the client library.  

    // Process ArgumentException, InvalidOperationException, or similar.  
}  
}  

備註

ChangeOperationResponse 物件不可由此程式庫的使用者直接建構。 而是在列舉透過 DataServiceResponse 類別上之列舉程式傳回的作業回應時,傳回參考。

SaveChanges 會將上次呼叫 DataServiceContext 之後 SaveChanges 所收集的擱置中變更送出到資料服務。 變更是透過呼叫 AddObjectAddLinkDeleteObjectDeleteLinkDetachDetachLink 和類似方法加入到內容。

SaveChanges 會傳回 DataServiceResponse,代表傳送到資料服務的所有作業回應。 DataServiceResponse 物件包含一連串的 ChangeOperationResponse 物件,其中依序包含一連串的 EntityDescriptorLinkDescriptor 執行個體,表示持續性或嘗試性的變更。

屬性

Descriptor

取得變更作業修改的 EntityDescriptorLinkDescriptor

Error

取得作業擲回的錯誤。

(繼承來源 OperationResponse)
Headers

在衍生類別中覆寫時,包含與單一作業相關聯的 HTTP 回應標頭。

(繼承來源 OperationResponse)
StatusCode

在衍生類別中覆寫時,取得或設定與單一作業相關聯的 HTTP 回應碼。

(繼承來源 OperationResponse)

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於