title: An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key
body: <p>I have following code to add or update the Entity object. finding the object by primary key, based on the response I am adding or updating the object.</p>
  
  <p>Adding record works, but during update its giving this error message "<strong>An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key"</strong></p>
  
  <p>In my MSSQL database I have only one record.</p>
  
  <pre><code>var v = db.Envelopes.Find(model.ReportDate, model.Service);
  if (v == null)
  {
      db.Envelopes.Add(model);
      db.SaveChanges();
      ViewBag.status = "Record Add successfully";
      ModelState.Clear();
  }
  else
  {
      db.Entry(model).State = EntityState.Modified;
      db.SaveChanges();
  }
  </code></pre>
  
  <p>How can I fix this error message?</p>