title: How to solve DbUpdateConcurrencyException when updating a row?
body: <p>I'm using the entity framework code first approach for an ASP.NET MVC application.  After editing a row when submitting for saving the change I'm getting the following error for the http post method:</p>
  
  <blockquote>
    <p>An exception of type
    'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException'
    occurred in EntityFramework.dll but was not handled in user code.</p>
  </blockquote>
  
  <p>This error is encountered at db.SaveChanges().</p>
  
  <pre><code>db.Entry&lt;Project&gt;(EditedProj).State = System.Data.Entity.EntityState.Modified;
  db.SaveChanges();
  </code></pre>
  
  <p>Main code:</p>
  
  <pre><code>[HttpGet]
  public ActionResult Edit(int id)
  {
      using (var db = new ProjectContext())
      {
          return View(db.Projects.Find(id));
      }
  }
  
  [HttpPost]
  public ActionResult Edit(Project EditedProj)
  {
      using (var db = new ProjectContext())
      {
          db.Entry&lt;Project&gt;(EditedProj).State = 
               System.Data.Entity.EntityState.Modified;
          db.SaveChanges();
          return RedirectToAction("Projects");
      }
  }
  </code></pre>