Compartir a través de


Clase ChangeOperationResponse

Resultados devueltos después de una llamada a SaveChanges al enumerar las respuestas de operación devueltas por la clase DataServiceResponse.

Jerarquía de herencia

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

Espacio de nombres:  System.Data.Services.Client
Ensamblado:  Microsoft.Data.Services.Client (en Microsoft.Data.Services.Client.dll)

Sintaxis

'Declaración
Public NotInheritable Class ChangeOperationResponse _
    Inherits OperationResponse
'Uso
Dim instance As ChangeOperationResponse
public sealed class ChangeOperationResponse : OperationResponse
public ref class ChangeOperationResponse sealed : public OperationResponse
[<SealedAttribute>]
type ChangeOperationResponse =  
    class
        inherit OperationResponse
    end
public final class ChangeOperationResponse extends OperationResponse

El tipo ChangeOperationResponse expone los siguientes miembros.

Propiedades

  Nombre Descripción
Propiedad pública Descriptor Obtiene el EntityDescriptor o el LinkDescriptor modificado por una operación de cambio.
Propiedad pública Error Obtiene el error producido por la operación. (Se hereda de OperationResponse.)
Propiedad pública Headers Cuando se invalida en una clase derivada, contiene los encabezados de respuesta HTTP asociados a una única operación. (Se hereda de OperationResponse.)
Propiedad pública StatusCode Cuando se invalida en una clase derivada, obtiene o establece el código de respuesta HTTP asociado a una única operación. (Se hereda de OperationResponse.)

Arriba

Métodos

  Nombre Descripción
Método público Equals (Se hereda de Object.)
Método protegido Finalize (Se hereda de Object.)
Método público GetHashCode (Se hereda de Object.)
Método público GetType (Se hereda de Object.)
Método protegido MemberwiseClone (Se hereda de Object.)
Método público ToString (Se hereda de Object.)

Arriba

Comentarios

Los objetos ChangeOperationResponse no están pensados para que los construya directamente un usuario de esta biblioteca. En su lugar, se devuelven referencias al enumerar las respuestas de la operación devueltas a través del enumerador en la clase DataServiceResponse.

SaveChanges envía los cambios pendientes al servicio de datos recopilados por DataServiceContext desde la última llamada a SaveChanges. Los cambios se agregan al contexto llamando a AddObject, AddLink, DeleteObject, DeleteLink, Detach, DetachLink y métodos similares.

SaveChanges devuelve DataServiceResponse que representa la respuesta a todas las operaciones enviadas al servicio de datos. El objeto DataServiceResponse incluye una secuencia de objetos ChangeOperationResponse que, a su vez, contienen una secuencia de instancias de EntityDescriptor o LinkDescriptor que representan los cambios que se guardaron o se intentaron realizar.

Ejemplos

El código siguiente muestra cómo procesar los resultados de una llamada a 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.
}
}

Seguridad para subprocesos

Cualquier miembro público static (Shared en Visual Basic) de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Vea también

Referencia

Espacio de nombres System.Data.Services.Client