This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
We are trying to handle a use case where we want to make some modifications to a record, call BeginEdit, make some other changes to the record, call SaveChanges, then if the database returns an error, call CancelEdit to revert the record to the state it was in prior to calling BeginEdit and return the record to the [HttpGet] Edit Action of the UserAccount Controller. Is there a way to persist the _backup state through calling SaveChanges to achieve this functionality? In trying to achieve this functionality, we stumbled upon the following issue: The 2 pieces of code below will result in different values being saved to the database. 1.
var record = UnitOfWork.FindById 2.
var record = UnitOfWork.FindById In the first example, the value "EndEdit was never called." will be saved to the database, in the second example, record.Description will remain unmodified. |
|
|
No but you could look at using a ChangeTracker and then reverting your changes manually. I presume you are avoiding just refreshing the entity from the database because the state of the entity prior to BeginEdit potentially contains other modifications since the last persistance call? In terms of the ambiguous behaviour, BeginEdit/EndEdit does rely on you not manipulating the entity state prior to entering into that transaction which is why you see it save in scenario 1 but not 2. The actual value is only rolled back when you call CancelEdit but in #1 the Description field has previously already been marked as dirty.
|
|