locked
Restore Entity to Original State RRS feed

  • Question

  • Can someone provide a sample of reverting a linq entity and all of it's children to their original states?  This includes removing new children added to EntitySets and restoring children that are deleted from EntitySets.

     

    Assume the RDB structure being modeled is:

     

    Orders

    Orders->OrderDetails

    Orders->Notes

     

    Changes have been made to all 3 table entities.

     

    Thanks.

    Brian

     

    Tuesday, December 4, 2007 4:55 PM

Answers

  • There is no built-in mechanism to revert your objects back to their original state.

     

    Tuesday, December 4, 2007 5:28 PM

All replies

  • There is no built-in mechanism to revert your objects back to their original state.

     

    Tuesday, December 4, 2007 5:28 PM
  • Matt, do you know, is this is planing to relization (N-level UndoChanges method)?

    Sunday, December 9, 2007 10:42 AM
  • After some testing I've found the best way to forget changes is to Dispose the DataContext and create a new one.

     

    Brian

    Sunday, December 9, 2007 8:06 PM
  •  

    You can manually add an instance of entity to an extention partial class along with a clone method to copy the object.  Then you attach to the OnLoad event and make a copy of the original.  You can then use this copy if you have to reattach a disconnected object or if you just want to restore to the original values:

     

    http://www.rockymoore.com/TheCoder/archive/2007/11/03/LINQ_Disconnected_Attach_no_Change_tracking_fix.aspx

     

    Another method is to call the Refresh method on the DataContext and have it pull the original back from the database with another hit on the database such as:

     

    MyDataContext.Refresh(RefreshMode.OverwriteCurrentValues);

     

     

    Tuesday, December 11, 2007 1:25 AM
  • MyDataContext.Refresh(RefreshMode.OverwriteCurrentValues); 

    The above method will not clear ChangeSet.

     

    Thursday, March 25, 2010 5:15 PM