This question is locked. New answers and comments are not allowed.
Hi,
In your example on this page (http://www.telerik.com/help/openaccess-orm/developer-guide-crud-saving-concurrency-conflicts.html), I don't understand the difference between Telerik.OpenAccess.RefreshMode.OverwriteChangesFromStore and Telerik.OpenAccess.RefreshMode.PreserveChanges.
From what I understand, PreserveChanges should "preserve" the modified values of the object and OverwriteChangesFromStore should "overwrite" the values of the object from the database. When I try to run your example and an exception occurred, the object is now updated base on the new values read from the database. I assume calling PreserveChanges would retain the modified values of the object. In this case, it is not.
From the documentation: "The PreserveChanges value means that the actual changes in the object will be kept but all clean data will be re-read."
How do I make sure the changes in the object are kept when an exception occurred? In this scenario when inside the exception, the object is now updated with the new values from the database.
- Dennis
In your example on this page (http://www.telerik.com/help/openaccess-orm/developer-guide-crud-saving-concurrency-conflicts.html), I don't understand the difference between Telerik.OpenAccess.RefreshMode.OverwriteChangesFromStore and Telerik.OpenAccess.RefreshMode.PreserveChanges.
From what I understand, PreserveChanges should "preserve" the modified values of the object and OverwriteChangesFromStore should "overwrite" the values of the object from the database. When I try to run your example and an exception occurred, the object is now updated base on the new values read from the database. I assume calling PreserveChanges would retain the modified values of the object. In this case, it is not.
From the documentation: "The PreserveChanges value means that the actual changes in the object will be kept but all clean data will be re-read."
using ( EntitiesModel dbContext = new EntitiesModel() )
{
Category categoryToUpdate = dbContext.Categories.FirstOrDefault();
// Let's assume CategoryName has the original value of "Orig-Name", then we change it to "NewName"
categoryToUpdate.CategoryName = "NewName";
try
{
// Before saving, the DB was modified externally and CategoryName is now "Mod-Name"
dbContext.SaveChanges();
}
catch ( Telerik.OpenAccess.Exceptions.OptimisticVerificationException ex )
{
// When exception occurred, the CategoryName is now "Mod-Name"
// Calling PreserveChanges does not preserve the value of the object
dbContext.Refresh(Telerik.OpenAccess.RefreshMode.PreserveChanges, categoryToUpdate);
// In your example, whether PreserveChanges or OverwriteChangesFromStore, you set the name of CategoryName
// Why the value of the object is not preserved after Refresh with PreserveChanges mode?
categoryToUpdate.CategoryName = "NewName";
dbContext.SaveChanges();
}
}
How do I make sure the changes in the object are kept when an exception occurred? In this scenario when inside the exception, the object is now updated with the new values from the database.
- Dennis