ChangeOperationResponse Classe
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Risultati restituiti dopo una chiamata a SaveChanges() durante l'enumerazione delle risposte dell'operazione restituite dalla DataServiceResponse classe .
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à
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
ChangeOperationResponse gli oggetti non devono essere costruiti direttamente da un utente di questa libreria. I riferimenti vengono invece restituiti durante l'enumerazione delle risposte dell'operazione restituite tramite l'enumeratore nella DataServiceResponse classe .
SaveChanges invia le modifiche in sospeso al servizio dati raccolto dall'ultima DataServiceContext chiamata a SaveChanges. Le modifiche vengono aggiunte al contesto chiamando AddObject, AddLink, DeleteObjectDeleteLink, Detach, , DetachLink, e metodi simili.
SaveChanges restituisce un DataServiceResponse oggetto che rappresenta la risposta a tutte le operazioni inviate al servizio dati. L'oggetto DataServiceResponse include una sequenza di ChangeOperationResponse oggetti che, a sua volta, contengono una sequenza di EntityDescriptor istanze o LinkDescriptor che rappresentano le modifiche persistenti o tentate.
Proprietà
| Nome | Descrizione |
|---|---|
| Descriptor |
Ottiene l'oggetto EntityDescriptor o LinkDescriptor modificato da un'operazione di modifica. |
| Error |
Ottiene l'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 singola operazione. (Ereditato da OperationResponse) |
| StatusCode |
In caso di override in una classe derivata, ottiene o imposta il codice di risposta HTTP associato a una singola operazione. (Ereditato da OperationResponse) |
Metodi
| Nome | Descrizione |
|---|---|
| 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 il Type dell'istanza corrente. (Ereditato da Object) |
| MemberwiseClone() |
Crea una copia superficiale del Objectcorrente. (Ereditato da Object) |
| ToString() |
Restituisce una stringa che rappresenta l'oggetto corrente. (Ereditato da Object) |