This is for a WPF application.
Suppose I have an entity Post and I show a dialog to edit it. The dialog has Okay and Cancel buttons. The entity will be updated in the dialog. What if the Cancel button is clicked? How do I undo the changes? Obviously I can save each field and then restore each if the edit is to be canceled. Is there a more direct mechanism? The following is a simplified version of what I am doing.
Post? post = Grid.SelectedItem as Post;
if (post is null)
return;
EditPost ep = new(post);
bool? b = ep.ShowDialog();

Anandu G NathPosted Jan 25, 2024, 1:00 PM
b <> true then do the operation
Sam HobbsPosted Jan 19, 2024, 6:12 PM
If the program does nothing then the record will remain the same and I am asking what feature does Entity Framework provide for undoing the change. I am sorry, I thought it was obvious that I am not asking about how to not save the changes to disk. I think that what you mean by update is save the changes to disk. I am not asking about that. I am asking how to revert the changes in memory. When the EditPost dialog is shown and edits are done, the data in the DataGrid in the main window is changed too. If the user cancels the dialog then the changes need to be undone.
If the user changes a row in the DataGrid and clicks Okay then changes a different row and clicks Cancel then I need to be able to save (to disk) the first edit but not the second.
Sachin SinghPosted Jan 19, 2024, 4:51 AM
simply update when b is true else do nothing