title: Entity Framework creating new record instead of modifying existing one
body: <p>I'm using Entity Framework with an AS.NET MVC application. I need to allow the user to create new records and modify existing ones. I am able to fetch existing records no problem, but when I pass back in the edited entity and try to save it it creates a new one and saves it and leaves the original unmodified.</p>
  
  <p>I am getting the object from EF using the primary key (e.g. ID number for an employee record). I successfully retrieve it, and set the MergeOption like so:</p>
  
  <pre><code>Context.Sector.MergeOption = MergeOption.NoTracking;
  </code></pre>
  
  <p>I am able to trace that the object has the correct data (using the key of the original record) all the way down to the point where I call:</p>
  
  <pre><code>Context.SaveChanges();
  </code></pre>
  
  <p>However, after that, the new record is created instead of modifying the existing one.</p>
  
  <p>Is there something obvious I am missing here? I would have thought that retrieving the object and changing some of its values (not the ID) and saving it would just work, but obviously not.</p>
  
  <p>Thanks,</p>
  
  <p>Chris</p>