title: Entity framework edit primary key and add row
body: <p>I have an edit/create page for a model. When the user submits the form, it'll be added or updated to the database.</p>
  
  <p>After that happens, I want to redirect them back to the same form while keeping the same data, with a cleared out id as well as some other values.</p>
  
  <pre><code>public ActionResult AddProduct(MyModel myModel)
  {
      // Save
      if (myModel.AuditID != 0) {
          Update(myModel);
      } else {
          Add(myModel);
      }
  
      // Set some values so it's seen as new, as well as some 
      // other values that need to be cleared
      myModel.ID = 0;
      myModel.Product = "";
  
      // Edit/Create page
      ActionResult ret = EditCreateKnownRow(myModel);
  
      return ret;
  }
  </code></pre>
  
  <p>I want it to be treated as a completely new entity, but I get an <code>InvalidOperationException</code> with these details:</p>
  
  <p><code>The property 'ID' is part of the object's key information and cannot be modified.</code></p>
  
  <p>I get that entity framework doesn't want to deal with the foreign key constraints that may exist, but that has nothing to do with what I'm looking for. Is there a way to treat it as a new entity without having to create a copy constructor?</p>
  
  <p>Thanks.</p>
  
  <p>Would doing something to the ModelState help? I've tried <code>ModelState.Remove(myModel.ID.ToString());</code> and <code>ModelState.Clear();</code> before modifying the key, but it didn't work.</p>