Print Page | Close Window

Undo Delete

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1954
Printed Date: 30-Aug-2025 at 10:32am


Topic: Undo Delete
Posted By: cjohnson84
Subject: Undo Delete
Date Posted: 08-Jul-2010 at 12:10pm
I have an observable collection that is bound to a datagrid.  I have a templated column that contains a "Delete" button for each row.  When the user clicks the "Delete" button for a specific row the entity is "marked" for deletion.  Programmatically I do this with the following line:
 
entity.EntityAspect.Delete();
 
Eventually when the user clicks a "Save" button the entity is truly deleted from the database.
 
My question is, once a row in the datagrid is marked for deletion I would like to be able to allow the user to click the "Delete" button again to "undo" the delete operation.
 
How do I achieve this?
 
I was looking at
 
entity.EntityAspect.AcceptChanges()
 
this sets the state of the entity to "Detached" though...I want set the state of the entity back to "Unchanged" as if it was never touched at all but EntityState is read only.



Replies:
Posted By: smi-mark
Date Posted: 08-Jul-2010 at 12:21pm
entity.EntityAspect.RejectChanges()


Posted By: Robert R
Date Posted: 04-Nov-2010 at 8:40am
Is there any way to undo only the deletion without rejecting all changes to the entity?
 
I have a situation similar to the original post.  If the user made changes to properties of the entity, but then deletes it and then undeletes it, I would like those property changes to still be in effect.
 


Posted By: sbelini
Date Posted: 04-Nov-2010 at 10:23am
Hi,
 
You could AcceptChanges before Delete'ing the entity. Later, if you need to undelete the entity, you would use SetModified.
 
A drawback is that, if you undelete, once you SaveChanges, that entity will be "resaved". (i.e. travel accross the wire)
 
 
I hope this helps.



Print Page | Close Window