Print Page | Close Window

Add ability to create child entitymanager

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=2187
Printed Date: 29-Jul-2026 at 4:17am


Topic: Add ability to create child entitymanager
Posted By: bigyes
Subject: Add ability to create child entitymanager
Date Posted: 23-Sep-2010 at 10:06am
It would be great if we could create a child entitymanager from an existing entitymanager. A child would be able to see (and update) its parents already loaded entities. An entity would stay unique in a complete entitymanager hierarchy.
AcceptChanges()/RejectChanges() would only occurs on a top>down basis against this hierarchy.
 
With this, I could start a use case with its own entityManager but having already some "reference data" entities in cache.
 
I can do that using :

DXGridServerModeDBEntities _ctx = new DXGridServerModeDBEntities();

_ctx.CacheStateManager.RestoreCacheState(_refDataCtx.CacheStateManager.GetCacheState());

but "reference data" entities are duplicated.

Do you think entitymanager hierarchy is a good idea ?
 



Replies:
Posted By: sbelini
Date Posted: 23-Sep-2010 at 12:35pm
Hi,
 
How about creating an "ChildEntityManager" and importing into it Entities from a "ParentEntityManager" by using ImportEntities(IEnumerable entities,   MergeStrategy mergeStrategy)?
Afterwards, you could import the Entities back to the ParentEntityManager with any changes that happen to be made (AcceptChanges()/RejectChanges() would only apply to the entity within one entity manager or the other).
 
You can find more details in the http://drc.ideablade.com/xwiki/bin/view/Documentation/SavingBusinessObjects#HDependencyGraphRetrieval - DevForce Resource Center .


Posted By: jsobell
Date Posted: 23-Sep-2010 at 11:21pm
Funny you should ask for this, I was discussing exactly the same thing with Ward last week :)
I presume you're trying to implement a 'transaction' like structure so you can rollback changes to multiple child records, yet have their changes written to the parent manager when you save them.



Posted By: smi-mark
Date Posted: 24-Sep-2010 at 12:11pm
You could probably write some sort of wrapper around the EntityManager. When you initialize it, it will load in the main entities, and upon calling the wrapped save function, it will save from the child EM, and then import back into the primary EM. Wouldn't be too difficult to write.



Print Page | Close Window