Question

I'm working with Self tracking entities. and when i Attach an entity to the context, all the entities related to it and the entity itself gets added in an added state in the context objectstatemanager. where as in the entity itself they have a different status, for example unchanged.

How can i attach an entity to the context whilst keeping the right state? (the objectstate in the entity)

i've tried detect changes but it does nothing. i hoped that detect changes would synchronize the object state of the context to the object state of the entity.

Was it helpful?

Solution

If you are using self tracking entities you should not use Attach, AddObject or DetectChanges directly. You should instead use ApplyChanges extension method defined on ObjectSet. This method will internally attach entities to the context and set current state based on the state stored in self tracking entities.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top