Undelete Child Object

Undelete Child Object

Old forum URL: forums.lhotka.net/forums/t/5748.aspx


AndyW posted on Thursday, November 06, 2008

Hi,

How do I set a child object that has been set to delete, to undelete.  Is this possible?

Basically when a user un-checks a checkbox in my checkboxlist custom control I set the child object to delete, however they then can re-tick the checkbox at which point I want to remove the deleted flag from the child object.

Thanks
Andy

AbbasMalik replied on Friday, January 17, 2014

Hi

I need to undelete a child object. How can I do this? An urgent solution will be highly appreciated.

Thanks

cfarren replied on Sunday, January 19, 2014

In response to the OP. Marking the object as New will remove the deleted flag.

In response to Abbas, I'll need some more information. That being said, you can navigate through the deleted list in your listing class to find all the child objects set for deletion when the DataPortal is called.

JonnyBee replied on Monday, January 20, 2014

One other possibility is to add your own editable property (ToBeDeleted or IsActive) and create your own filter on top of the list. 

If the user is allows to "delete" / "undelete" in a checkbox then maybe the MarkDeleted mechanism isn't the appropriate one to use. 

So when needed - I have created:

AbbasMalik replied on Wednesday, January 22, 2014

Thanks for your response.

What is the philosophy behind not having an Undelete() method?

JonnyBee replied on Wednesday, January 22, 2014

Objects that is deleted in a list (typically) is moved to a new internal list for Deleted items. 

There is no guarantee that the user may already have added a new row in the list that have the same primary key or unique key fields so that it _may_ not be safe to "undelete" the item. 

So the safe processing when saving is to process 

AbbasMalik replied on Thursday, January 23, 2014

Hi Jonny,

Thanks for explaining the logic.

I have 1:1 relation between parent and an optional child. And if the child is marked as deleted, then I have no way to undelete it or create a new child. Due to this limitation, I have to use a child collection instead of a single child. With collections, it is fine to delete and then recreate the new object.

Best regards

Abbas

cfarren replied on Thursday, January 23, 2014

If you can mark it as deleted then why can't you mark it as new when you want to undelete it?

AbbasMalik replied on Friday, January 24, 2014

Thanks cfarren

I can call MarkNew() and then MarkOld() to achieve the Undelete() effect. I hope this will work. Thanks for pointing out in the rigght direction.

Best regards

Abbas

ngm replied on Sunday, January 26, 2014

Abbas,

Depending on the scenario, you might consider n-level undo as an option as well.

MarkNew/MarkOld should work as long as you don't have any logic handling PropertyChanged notification for IsNew property twice where object is new and then once again when it's old.

- ngm

Abbas

Thanks cfarren

I can call MarkNew() and then MarkOld() to achieve the Undelete() effect. I hope this will work. Thanks for pointing out in the rigght direction.

Best regards

Abbas

aimee replied on Saturday, January 25, 2014

this is unbelieveable!

Copyright (c) Marimer LLC