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 オブジェクトのシーケンスが含まれます。さらに、これらの各オブジェクトには、永続化または試行された変更を表す、EntityDescriptor インスタンスまたは LinkDescriptor インスタンスのシーケンスが含まれます。

プロパティ

Descriptor

変更操作で変更された EntityDescriptor または LinkDescriptor を取得します。

Error

操作でスローされたエラーを取得します。

(継承元 OperationResponse)
Headers

派生クラスでオーバーライドされた場合、単一の操作に関連付けられている HTTP 応答ヘッダーが含まれます。

(継承元 OperationResponse)
StatusCode

派生クラスでオーバーライドされた場合、単一の操作に関連付けられている HTTP 応答コードを取得または設定します。

(継承元 OperationResponse)

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象