Diffing entities that have child and grand-child entities

Posts   
 
    
greenstone
User
Posts: 132
Joined: 20-Jun-2007
# Posted on: 12-Mar-2012 17:07:19   

Hi,

Using the LLBLGen 3.1, adapter.

My application has an "employee" entity with child entities and grand-child entities (hierarchical ancestors).

In the UI, each time a user goes into edit mode for an "employee" entity, the entity and all ancestor entites are fetched and stored in session (ASP.NET application). Any changes to the entity and ancestors (e.g. adding/deleting/changing entity or ancestor entities) are made to this hierarchy of entities.

Then upon a "save" the existing database entity (and all ancestors) are deleted, and the new employee entity (and all ancestors) are added.

This works fine, but it doesn't allow effective audting (because we're rewriting everything each time...when a subset of the ancestor entities may have really changed).

So what I think I need is a way to "diff" the "editing" entity (and ancestors) to the one that's currently held in the database. Suggestion on the best approach for this?

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 13-Mar-2012 10:11:54   

If you fetch a graph of entities and keep it in teh memory of your application (or session of ASP.NET), then whatever editing is done to this graph of entities, will be persisted to the database (UPDATE commands) once you Save the graph.

Just save the root entitiy while passing true for recursive save, and the entire graph will be saved.

there is no need for deletes and re-inserts.

greenstone
User
Posts: 132
Joined: 20-Jun-2007
# Posted on: 13-Mar-2012 12:37:48   

Thanks for the quick response.

Just to be sure I understand, saving the root entity (with the "true") will delete/add/update all ancestor entities that don't exist/are new/are updated?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Mar-2012 21:36:55   

That's right. They will update/insert entities that were modified/added in the EntityCollection. For the deleted ones is a little bit different, because the fact that you remove an entity from a collection doesn't strictly means that you want to remove it from the persistence storage (DB). Howerver you can track the entities that were removed from the collection and then take an action on that, for instance you can delete them all from the DB, to learn more about this read Tracking entity remove actions.

David Elizondo | LLBLGen Support Team