title: Error while updating Database record with Entity Framework on ASP.NET MVC Page
body: <p>I have an ASP.NET Page that updates registered User Address Details for a selected record.</p>
  
  <p>Below is the update method that I am calling from my controller.</p>
  
  <p>When I am calling the <code>ApplyPropertyChanges</code> method, I am getting an error. Did anyone run into the same error while updating the record with Entity Framework?</p>
  
  <p>Appreciate your responses.</p>
  
  <p>Error message:</p>
  
  <blockquote>
    <p>The existing object in the ObjectContext is in the Added state. Changes can only be applied when the existing object is in an unchanged or modified state.</p>
  </blockquote>
  
  <p>My <code>Update</code> method:</p>
  
  <pre><code>[HttpPost]
  public bool UpdateAddressDetail([Bind(Prefix = "RegUser")] AddressDetail regUserAddress, FormCollection formData)
  {
      regUserAddress.AD_Id = 3;
      regUserAddress.LastUpdated = HttpContext.User.Identity.Name;
      regUserAddress.UpdatedOn = DateTime.Now;
      regUserAddress.AddressType = ((AddressDetail)Session["CurrentAddress"]).AddressType ?? "Primary";
      regUserAddress.Phone = ((AddressDetail)Session["CurrentAddress"]).Phone;
      regUserAddress.Country = ((AddressDetail)Session["CurrentAddress"]).AddressType ?? "USA";
  
      miEntity.ApplyPropertyChanges(regUserAddress.EntityKey.EntitySetName, regUserAddress);
  
      miEntity.SaveChanges();
  
      return true;
  }
  </code></pre>