Currently I'm a bit struggling with the RollbackTo function of SQLite. I want to undo some changes that are made (e.g. deleting an item, changing a property of the item), so I make use of transactions. I've made an RunInTransactionWithUndoAsync extension for the SQLiteConnection. It performs the following steps:
It saves a transaction point, saved in a var
It invokes the action, e.g. updating a bunch of items
It tells the UI (using MVVM messaging) to show a dialog for five seconds that gives the user the chance to undo his changes
Meanwhile a Task.Delay(5000) is executed.
If the user doesn't do anything, the changes will be committed via Commit(). Otherwise they will be undone through RollbackTo(transactionPoint)
So far, so good. Anything related to the database works fine, but there's one problem. When I'm undoing the changes the UI changes will be reverted as well, which would be fine, if it would work correctly. So when I'm marking item 5 from 100 items in my ObservableCollection<ItemViewModel> on my MainViewModel as read (in my example; it's just a boolean) and rollback those changes, SQLite adds the last item (item 100) another time to the collection, which is not the wanted behavior. If you could explain to me why this is happening, that would be nice. It's not my code who's doing the UI changes after rollback, because even after commenting out all the places, where I modify that collection, the CollectionChanged event fires after a rollback.
Currently I'm a bit struggling with the
RollbackTo
function of SQLite. I want to undo some changes that are made (e.g. deleting an item, changing a property of the item), so I make use of transactions. I've made anRunInTransactionWithUndoAsync
extension for the SQLiteConnection. It performs the following steps:var
Task.Delay(5000)
is executed.Commit()
. Otherwise they will be undone throughRollbackTo(transactionPoint)
So far, so good. Anything related to the database works fine, but there's one problem. When I'm undoing the changes the UI changes will be reverted as well, which would be fine, if it would work correctly. So when I'm marking item 5 from 100 items in my
ObservableCollection<ItemViewModel>
on myMainViewModel
as read (in my example; it's just a boolean) and rollback those changes, SQLite adds the last item (item 100) another time to the collection, which is not the wanted behavior. If you could explain to me why this is happening, that would be nice. It's not my code who's doing the UI changes after rollback, because even after commenting out all the places, where I modify that collection, theCollectionChanged
event fires after a rollback.