expose EntityBase2._editCycleInProgress

Posts   
 
    
omar avatar
omar
User
Posts: 569
Joined: 15-Oct-2004
# Posted on: 07-Mar-2005 10:10:27   

Greetings,

EntityBase2 implements IEditableObject interface for data-binding support. One situation I am facing is implementing my own version of recursive delete in my derived entity classes. In a screen, a user can edit an entity and its related collections in child grids. During this edit session the user can choose to delete any entity record from any of the related entity collection grids. After that the user can either CANCEL-EDIT or SAVE. If the user CANCELs his edit then the enitity must be rolled-back to its original state along with discarding any changes to all the related collections (any newly added records to the collections is discarded and any deleted records from the child collections is retreived). This is best done through binary serialization (as Frans has suggested in my previous post which I am still struggeling to get it right). If the user SAVES his changes this meens: 1- recusrivly save all changes (inserts and updates) to all related collections as well as the entity itself. This is done excellently by the LLBL classes 2- delete all child entities removed from any of the child grids during this edit session. Currently LLBL's classes do not perform recursive delete for reasons Frans explained. To implement that functionality I needed to trap all removed child entities in a local buffer (in my derived entity class) and ONLY when the edit session is ended I would save the entity and delete any removed child entities in a single transaction. The only missing piece of information here is that I need to know WHEN an edit session has started so that I would start buffering away all removed child entities in the related collecion's BeforeRemove event. For me to know that I need the base EntityBase2's (_editCycleInProgress) flag which gets set when IEditableObject's EditObject first gets called. I present this case so as to escelate the scope of this flag to be protected (ReadOnly ofcourse) so that derived classes can utilize it in situations similar to the one explained above.

Sorry for the long post... disappointed

Note: I tried shadowing the IEditableObject methods in my derived class but then my UI code could NOT be written in a generic manner bu rather has to be strobgly typed to the derived entity type I am shadowing the methods in...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39752
Joined: 17-Aug-2003
# Posted on: 07-Mar-2005 10:43:31   

the IEditableObject interface methods get called a lot during a session. I'm not sure if you want that information, because I don't think you can use it. What I don't see is why you don't build up your information to process (deletes, saves) during the actions of the user in the form. If the user clicks Save, you KNOW the edit cycle is over, and can just proceed with saving the changes. If the user clicks Cancel, you also know the edit cycle is over and can just throw away what you've collected and revert the serialized data back into an object graph.

So I think it's more useful for you to hook into for example grid events when the user does something, as IEditableObject.BeginUpdate is called for example when a user enters a cell, moves to another row (thus entering a cell on another row calls this method twice) and cancel edit is called twice if the user presses ESC twice (once for the cell, once for the row).

Frans Bouma | Lead developer LLBLGen Pro