Export (0) Print
Expand All

ChangeOperationResponse Class

Results returned after a call to SaveChanges when enumerating operation responses returned by the DataServiceResponse class.

System.Object
  System.Data.Services.Client.OperationResponse
    System.Data.Services.Client.ChangeOperationResponse

Namespace:  System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)

public sealed class ChangeOperationResponse : OperationResponse

The ChangeOperationResponse type exposes the following members.

  NameDescription
Public propertyDescriptorGets the EntityDescriptor or LinkDescriptor modified by a change operation.
Public propertyErrorGets error thrown by the operation. (Inherited from OperationResponse.)
Public propertyHeadersWhen overridden in a derived class, contains the HTTP response headers associated with a single operation. (Inherited from OperationResponse.)
Public propertyStatusCodeWhen overridden in a derived class, gets or sets the HTTP response code associated with a single operation. (Inherited from OperationResponse.)
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

ChangeOperationResponse objects are not intended to be constructed directly by a user of this library. Instead, references are returned when enumerating the operation responses returned via the enumerator on the DataServiceResponse class.

SaveChanges submits pending changes to the data service collected by the DataServiceContext since the last call to SaveChanges. Changes are added to the context by calling AddObject, AddLink, DeleteObject, DeleteLink, Detach, DetachLink, and similar methods.

SaveChanges returns a DataServiceResponse that represents the response to all operations sent to the data service. The DataServiceResponse object includes a sequence of ChangeOperationResponse objects that, in turn, contain a sequence of EntityDescriptor or LinkDescriptor instances that represent the changes that were persisted or attempted.

The following code shows how to process the results of a call to 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.
}
}

.NET Framework

Supported in: 4.5, 4, 3.5 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft