asp.net mvc - Entity Framework creating new record instead of modifying existing one -
I am using unit framework with an as.net MVC application. I have the user permission to create new records and modify existing ones. I am unable to bring any problems to existing records, but when I pass back into the edit unit and try to save it, it creates a new one and saves it and leaves the original unconnected.
I get the object, I successfully recover it from EF using the primary key (such as the ID number for an employee record), and set MergeOption in this way:
Context.Sector.MergeOption = MergeOption.No Tracking;
I can find that the right data in the object (using the key of the original record), as far as I call:
Context.SaveChanges ();
However, after this, the new record has been created instead of modifying the existing record.
Am I missing something? I would have thought that to recover the object and change some of its values (id) and saving it will only work, but not clearly.
Thanks
NoTracking means that objectstate manager is bypassed and therefore each access to the unit object is brought from the database and new items "
-
I do not think what you want is nautriking.
Comments
Post a Comment