title: Edit Id - Store update, insert, or delete statement affected an unexpected number of rows (0)
body: <p>So I need to be able to edit my primary key field in my edit page for a row, I get the error</p>
  
  <blockquote>
    <p>Store update, insert, or delete statement 
    affected an unexpected number of rows (0). 
    Entities may have been modified or deleted
    since entities were loaded. Refresh ObjectStateManager entries.</p>
  </blockquote>
  
  <p>When I don't change the primary key field I can save all my other changes to my database.</p>
  
  <p>This is my edit function.</p>
  
  <pre><code>//edit - post
  [HttpPost]
  public ActionResult ActiveCampaignsEdit(ActiveCampaign activecampaign)
  {
    try
    {
      if (ModelState.IsValid)
      {
        db.Entry(activecampaign).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("ActiveCampaigns");
      }
    }
    catch (DataException err)
    {
      //Log the error (add a variable name after DataException)
      ModelState.AddModelError(string.Empty, err.Message);
    }
    ViewBag.TypesList = new SelectList(db.Types, "TypeId", "TypeName");
    ViewBag.CaptureFormsList = new SelectList(db.CaptureForms, "Id", "Name");
    ViewBag.AssignedUsersList = new SelectList(db.Users, "Id", "Username");
    return View(activecampaign);
  }
  </code></pre>
  
  <p>How would I go about editing the Primary Key, or am I approaching this in the wrong way?</p>