|
Este artículo proviene de un motor de traducción automática. Mueva el puntero sobre las frases del artículo para ver el texto original. Más información.
|
Traducción
Original
|
ObjectContext.SaveChanges (Método)
Espacio de nombres: System.Data.Objects
Ensamblado: System.Data.Entity (en System.Data.Entity.dll)
Valor devuelto
Tipo: System.Int32| Excepción | Condición |
|---|---|
| OptimisticConcurrencyException |
using (AdventureWorksEntities context = new AdventureWorksEntities()) { try { // Perform an operation with a high-level of concurrency. // Change the status of all orders without an approval code. ObjectQuery<SalesOrderHeader> orders = context.SalesOrderHeaders.Where( "it.CreditCardApprovalCode IS NULL").Top("100"); foreach (SalesOrderHeader order in orders) { // Reset the order status to 4 = Rejected. order.Status = 4; } try { // Try to save changes, which may cause a conflict. int num = context.SaveChanges(); Console.WriteLine("No conflicts. " + num.ToString() + " updates saved."); } catch (OptimisticConcurrencyException) { // Resolve the concurrency conflict by refreshing the // object context before re-saving changes. context.Refresh(RefreshMode.ClientWins, orders); // Save changes. context.SaveChanges(); Console.WriteLine("OptimisticConcurrencyException " + "handled and changes saved"); } foreach (SalesOrderHeader order in orders) { Console.WriteLine("Order ID: " + order.SalesOrderID.ToString() + " Order status: " + order.Status.ToString()); } } catch (UpdateException ex) { Console.WriteLine(ex.ToString()); } }
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (no se admite el rol Server Core), Windows Server 2008 R2 (se admite el rol Server Core con SP1 o versiones posteriores; no se admite Itanium)
.NET Framework no admite todas las versiones de todas las plataformas. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.