ChangeOperationResponse-Klasse
Zurückgegebene Ergebnisse nach dem Aufrufen von DataServiceResponse, wenn Operationsantworten der Klasse SaveChanges nummeriert werden.
Vererbungshierarchie
System.Object
System.Data.Services.Client.OperationResponse
System.Data.Services.Client.ChangeOperationResponse
Namespace: System.Data.Services.Client
Assembly: Microsoft.Data.Services.Client (in Microsoft.Data.Services.Client.dll)
Syntax
'Declaration
Public NotInheritable Class ChangeOperationResponse _
Inherits OperationResponse
'Usage
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
Der ChangeOperationResponse-Typ macht folgende Elemente verfügbar.
Eigenschaften
Name | Beschreibung | |
---|---|---|
Descriptor | Ruft den EntityDescriptor ab, oder LinkDescriptor wurde durch einen Änderungsvorgang geändert. | |
Error | Ruft vom Vorgang ausgelösten Fehler ab. (Geerbt von OperationResponse.) | |
Headers | Enthält beim Überschreiben in einer abgeleiteten Klasse die einem einzelnen Vorgang zugeordneten HTTP-Antwortheader. (Geerbt von OperationResponse.) | |
StatusCode | Ruft beim Außerkraftsetzen in einer abgeleiteten Klasse den HTTP-Antwortcode zu einer Operation ab oder legt diesen fest. (Geerbt von OperationResponse.) |
Zum Anfang
Methoden
Name | Beschreibung | |
---|---|---|
Equals | (Geerbt von Object.) | |
Finalize | (Geerbt von Object.) | |
GetHashCode | (Geerbt von Object.) | |
GetType | (Geerbt von Object.) | |
MemberwiseClone | (Geerbt von Object.) | |
ToString | (Geerbt von Object.) |
Zum Anfang
Hinweise
ChangeOperationResponse-Objekte sind nicht gedacht dazu, von einem Benutzer dieser Bibliothek direkt erstellt zu werden. Stattdessen werden beim Nummerieren der Operationsantworten über die Nummerierung der Klasse DataServiceResponse Verweise zurückgegeben.
SaveChanges sendet ausstehende Änderungen an den seit dem letzten Aufruf von SaveChanges vom DataServiceContext gesammelten Datendienst. Dem Kontext werden Änderungen hinzugefügt, indem AddObject, AddLink, DeleteObject, DeleteLink, Detach, DetachLink und ähnliche Methoden aufgerufen werden.
SaveChanges gibt einen DataServiceResponse zurück, der die Antwort zu allen an den Datendienst gesendeten Vorgängen darstellt. Das DataServiceResponse-Objekt enthält eine Folge von ChangeOperationResponse-Objekten, die wiederum eine Folge von EntityDescriptor-Instanzen oder LinkDescriptor-Instanzen enthalten, die die beibehaltenen Änderungen oder Änderungsversuche darstellen.
Beispiele
Im folgenden Code wird gezeigt, wie die Ergebnisse eines Aufrufs von SaveChanges verarbeitet werden.
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.
}
}
Threadsicherheit
Alle öffentlichen static (Shared in Visual Basic)-Elemente dieses Typs sind Threadsicher. Für Instanzelemente wird die Threadsicherheit nicht gewährleistet.