New Posts New Posts RSS Feed: RejectChanges to Parent/Children
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

RejectChanges to Parent/Children

 Post Reply Post Reply
Author
scottarlp View Drop Down
Newbie
Newbie


Joined: 07-Apr-2011
Posts: 26
Post Options Post Options   Quote scottarlp Quote  Post ReplyReply Direct Link To This Post Topic: RejectChanges to Parent/Children
    Posted: 19-Dec-2011 at 6:20am
I must be having a brain cell strike. If I have a parent entity such as Order and create a new Order and then attach new OrderDetail entities to the relation, how do I go about rejecting all of them? I had thought that calling RejectChanges() on Order would also take care of the OrderDetail (nothing commited, just added), but what I'm seeing are OrderDetail records dangling in cache waiting to be saved.
 
I've got a generic Entity in my ViewModel for an edit dialog. It's not aware of the specific entity, so I call RejectChanges() on it if the user cancels. I was hoping I could keep this rather generic and possibly (if needed) cycle through any child relations and cancel them as well.
 
Thanks for your help.
Scott
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 19-Dec-2011 at 3:08pm
Hi Scott,
 
To reject all entity changes made you should call mgr.RejectChanges.
 
Note that this will roll back all entity changes since the cache was created or the last SaveChanges call was made, which might also roll back entity changes you don't want to.
 
When calling RejectChanges on an entity rather than on the entityManager, the call will not propagate to the entity's children. You could, however, accomplish it by using reflection. In this case, you'd 'travel' thru the entire entity's hierarchy, rejecting changes to all its children. (and possibly grandchildren, etc, if needed)
That will, however, be a laborious because you'd need to navigate thru all the entities to call RejectChanges.

Before going that path I'd suggest using a "sandbox" EM where you could call mgr.RejectChanges() or simply save and then merge the EntityCache of the sandbox mgr with the main entity manager. You will find detailed information about this approach in the DevForce Resource Center.
 
I hope this helps,
   Silvio
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down