New Posts New Posts RSS Feed: Entity State Change before entity add to manager
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Entity State Change before entity add to manager

 Post Reply Post Reply
Author
bstearns View Drop Down
Newbie
Newbie


Joined: 27-Jul-2010
Posts: 5
Post Options Post Options   Quote bstearns Quote  Post ReplyReply Direct Link To This Post Topic: Entity State Change before entity add to manager
    Posted: 16-Sep-2010 at 11:22am
Hello Everyone 
I am seeing something with my entity manager when adding a new entity that doesn't make sense to me.
From all my reading it seems that when I call 
 
X foo = EntityManger.CreateEntity<X>(); 
 
I will get a new instance of the entity of type X and its entity state will be detatched until I explicity call EntityManager.AddEntity(foo).
 
This is exactly how it works if my type X does not have property of another type on it.  The propblem seems to happen when I have a type X that has a property of type Y in it.  Then when I set the Type Y property the entity state then changes to added and if I look at the EntityManager.Xs I see the entity already attached there.
 
To try and illustrate this better here is my code:

TypeX foo= EntMan.CreateEntity<TypeX >();
 
//at this point foo has an entitystate = detatched and EntMan.TypeXs does not contain anything
foo.FooID = Guid.NewGuid();
foo.SomeProp1 = "Something";
            
//bar is a type that is already in cache and has an entity state = unchanged
foo.SomePropThatIsOfOtherTypeInCache = bar;
//after setting SomePropThatIsOfOtherTypeInCache we can see that
//foo.entitystate = added and EntMan.TypeXs now conatins the foo entity.
 
At this point because the entitystate is added and the entitymanager already contains the entity there is no reason to call EntityManager.AddEntity(foo).
 
I cannot find any documentation that mentions this functionality.  Is this by design or do I not understand how this is suppose to work.
 
Thanks
Blaine
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 16-Sep-2010 at 2:21pm
Hi Blaine;

Yes, what you are observing is by design. An entity is automatically added if any of its related entities are already in the EntityManager.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down