Share via


ChangeOperationResponse Classe

Definizione

I risultati restituiti dopo una chiamata a SaveChanges() durante l'enumerazione delle risposte dell'operazione restituite dalla classe 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
Ereditarietà
ChangeOperationResponse

Esempio

Nel codice seguente viene illustrato come elaborare i risultati di una chiamata 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.  
}  
}  

Commenti

Gli oggetti ChangeOperationResponse non devono essere costruiti direttamente da un utente di questa libreria. Al contrario, i riferimenti vengono restituiti durante l'enumerazione delle risposte dell'operazione restituite tramite l'enumeratore sulla classe DataServiceResponse.

L'oggetto SaveChanges invia al servizio dati le modifiche in sospeso raccolte da DataServiceContext dall'ultima chiamata a SaveChanges. Le modifiche vengono aggiunte al contesto chiamando AddObject, AddLink, DeleteObject, DeleteLink, Detach, DetachLink e metodi simili.

SaveChanges restituisce un DataServiceResponse che rappresenta la risposta a tutte le operazioni inviate al servizio dati. L'oggetto DataServiceResponse include una sequenza di oggetti ChangeOperationResponse che a loro volta contengono una sequenza di istanze di EntityDescriptor o LinkDescriptor che rappresentano le modifiche rese persistenti o che sono state tentate.

Proprietà

Descriptor

Ottiene l'oggetto EntityDescriptor o LinkDescriptor modificato da un'operazione di modifica.

Error

Ottiene un errore generato dall'operazione.

(Ereditato da OperationResponse)
Headers

Quando è sottoposto a override in una classe derivata, contiene le intestazioni di risposta HTTP associate a una sola operazione.

(Ereditato da OperationResponse)
StatusCode

Quando è sottoposto a override in una classe derivata, ottiene o imposta il codice di risposta HTTP associato a una sola operazione.

(Ereditato da OperationResponse)

Metodi

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetType()

Ottiene l'oggetto Type dell'istanza corrente.

(Ereditato da Object)
MemberwiseClone()

Crea una copia superficiale dell'oggetto Object corrente.

(Ereditato da Object)
ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)

Si applica a