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 返回表示对发送到数据服务的所有操作的响应的 DataServiceResponseDataServiceResponse 对象包括一系列 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)

适用于