title: .Net Core 3.1 MVC Web App - DbUpdateConcurrencyException when trying to update a record
body: <p>The other answers on here regarding this issue are to do with a missing primary key or id field. This is not the case here.</p>
  <p>So in my edit functionality, I am trying to edit a record from my ASPNetUsers table (Identity table). However I'm getting the following error message after my code hits the SaveChanges() method:</p>
  <blockquote>
  <p>DbUpdateConcurrencyException: Database operation expected to affect 1
  row(s) but actually affected 0 row(s). Data may have been modified or
  deleted since entities were loaded. See
  <a href="http://go.microsoft.com/fwlink/?LinkId=527962" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/?LinkId=527962</a> for information on
  understanding and handling optimistic concurrency exceptions.</p>
  </blockquote>
  <p>Here is my controller code:</p>
  <pre><code>[HttpPost]
          public async Task&lt;IActionResult&gt; Edit(string id, ApplicationUser applicationUser)
          {
              if (id == null)
              {
                  return NotFound();
              }      
  
  
              if (ModelState.IsValid)
              {
                  try
                  {
                      _context.Entry(applicationUser).State = EntityState.Modified;
                      _context.Users.Update(applicationUser);
                      await _context.SaveChangesAsync();
                  }
                  catch (DbUpdateConcurrencyException)
                  {
                      if (!MemberExists(applicationUser.Id))
                      {
                          return NotFound();
                      }
                      else
                      {
                          throw;
                      }
                  }
                  return RedirectToAction(nameof(Index));
              }
  
              return View(applicationUser);
  
          }
  </code></pre>
  <p>What I am trying to update is a row in the ASPNetUsers table. This is the table created when scaffolding microsoft identity into the project. See screenshot showing the values of the two passed in parameters.</p>
  <p><a href="https://i.stack.imgur.com/8zVLT.png" rel="nofollow noreferrer">screenshot with values of parameters</a></p>
  <p>Any tips would be appreciated, thanks</p>