Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF "undo" with deep copy

Current situation

I have a WPF application where I use MVVM and NHibernate. I have a master/detail window with a listbox with all my customers, and the selectedItem of the listbox is the object that is being used to display the customerdetails in the detailscreen. In the detailscreen I have an add, edit, delete, save and an undo buttton. Everything works with the binding I've set up.

Problem

But for my undo button I was thinking of making a copy of the original Customer object so when I click the undo button the field will be resetted to the values from the original values. But in my customer object I have an Address object and with a shallow copy the 2 objects will keep the same reference to that object. So when I change a field from the Address object the original Customer address will also be changed. I was thinking of doing a deep copy of my Customer address but I can't make my object serializable (It's not in my control to change the Model objects)

  • Is there any way to do a deep copy without serialization?
  • Or is there some standard way to accomplish the behavior I want to achieve?
like image 498
koala Avatar asked Dec 07 '25 09:12

koala


1 Answers

I would simply go back to the database and reload the customer object. That ensures that the data you're displaying is consistent with the data in the database and reduces the risk of concurrency issues.

like image 99
Jamie Ide Avatar answered Dec 09 '25 21:12

Jamie Ide



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!