Print Page | Close Window

multiple entity manager (second attempt)

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=2278
Printed Date: 29-Apr-2025 at 1:10am


Topic: multiple entity manager (second attempt)
Posted By: hueha
Subject: multiple entity manager (second attempt)
Date Posted: 30-Oct-2010 at 8:32am
I've finally got the motivation to have another crack at using multiple entity managers in my application.  I've managed to get it to work for editing an entity but having problems with adding a new entity.

I have a grid displaying a list of entities (lets say orders for an employee).  When I go to add a new entity these are the steps I'm going through.  I have an issue at step 5

1) Create a new entity
  _mgr.CreateEntity<Order>();
2) Create the new entity manager and copy this new item over
            var mgr2 = new MyEntities();
            mgr2.LinkForAuthentication(this);
            mgr2.EntityChanged += (s, args) => { if (args.Action == EntityAction.Delete) { _mgr.RemoveEntity(args.Entity); } };
            mgr2.ImportEntities(new Entity[] { root }, MergeStrategy.OverwriteChanges);
3) Make changes to this entity and save it

4) I copy the new  entity back into the main entity manager
_Mgr.ImportEntities(this.FindEntities(EntityState.Added | EntityState.Deleted | EntityState.Modified), MergeStrategy.OverwriteChanges);

5) The problem I have is at this point I would normally add to the new Entity to RelatedEntityList to make the order appear for that employee.  BUT how do I get a reference to the newly imported entity?



Replies:
Posted By: sbelini
Date Posted: 01-Nov-2010 at 3:15pm

On step 4 you have a collection with the imported entity (which, I assume, is the only entity in the collection):

 
_Mgr.ImportEntities(this.FindEntities(EntityState.Added | EntityState.Deleted | EntityState.Modified), MergeStrategy.OverwriteChanges);
 
So you can ref the entity from mgr2 and find it in _mgr by Key with FindEntity:
  
em2.FindEntity(myEntityInMgr2.EntityAspect.EntityKey);


Posted By: hueha
Date Posted: 01-Nov-2010 at 3:19pm
The collection is an entity graph.  That entity key thing should work just fine, thanks.



Print Page | Close Window