New Posts New Posts RSS Feed: multiple entity manager (second attempt)
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

multiple entity manager (second attempt)

 Post Reply Post Reply
Author
hueha View Drop Down
Newbie
Newbie


Joined: 23-Jul-2010
Posts: 38
Post Options Post Options   Quote hueha Quote  Post ReplyReply Direct Link To This Post Topic: multiple entity manager (second attempt)
    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?
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: 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);
Back to Top
hueha View Drop Down
Newbie
Newbie


Joined: 23-Jul-2010
Posts: 38
Post Options Post Options   Quote hueha Quote  Post ReplyReply Direct Link To This Post Posted: 01-Nov-2010 at 3:19pm
The collection is an entity graph.  That entity key thing should work just fine, thanks.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down