ChangeOperationResponse Clase
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Resultados devueltos después de una llamada a SaveChanges() al enumerar las respuestas de operación devueltas por la clase 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
- Herencia
En el código siguiente se 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.
}
}
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.
Descriptor |
Obtiene el EntityDescriptor o el LinkDescriptor modificado por una operación de cambio. |
Error |
Obtiene el error producido por la operación. (Heredado de OperationResponse) |
Headers |
Cuando se invalida en una clase derivada, contiene los encabezados de respuesta HTTP asociados a una única operación. (Heredado de OperationResponse) |
Status |
Cuando se invalida en una clase derivada, obtiene o establece el código de respuesta HTTP asociado a una única operación. (Heredado de OperationResponse) |
Equals(Object) |
Determina si el objeto especificado es igual que el objeto actual. (Heredado de Object) |
Get |
Sirve como la función hash predeterminada. (Heredado de Object) |
Get |
Obtiene el Type de la instancia actual. (Heredado de Object) |
Memberwise |
Crea una copia superficial del Object actual. (Heredado de Object) |
To |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |
Produto | Versións |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Comentarios de .NET
.NET é un proxecto de código aberto. Selecciona unha ligazón para ofrecer comentarios: