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
|