I have an Entity Framework 4.0 model implemented with pure POCO (without code generation, without self-monitoring objects, just old CLR objects).
Now here is the code I have in my user interface to execute UPDATE:
[HttpPost] public ActionResult UpdatePerson(Person person) { repository.Attach(person); unitOfWork.Commit(); }
Essentially, I have an action method that accepts a strongly typed Person object, and I need to UPDATE this entity.
Error, but also does not save changes to the database .: (
When I check the EntityState during the "Commit" of my module of work:
var entities = ObjectStateManager.GetObjectStateEntries(EntityState.Added | EntityState.Deleted | EntityState.Modified | EntityState.Unchanged);
I see my entity with EntityState.Unchanged .
So this explains why it has not survived. The operations "My Search", "Add", "Delete" work fine (they are saved correctly). But UPDATE does not seem to work.
I found several threads saying that I need to manually set the state of the object:
ctx.ObjectStateManager.ChangeObjectState(person, EntityState.Modified);
It is right? Where would I put this logic? Expose as an operation on my Unit of work?
Obviously, the problem is that I have change tracking , due to using Pure POCO (without EntityObject derivation, without INotifyPropertyChanging implementation).
But I still have not found a problem with it.
What am I doing wrong?