title: ASP.Net & EF Core 2 and Concurrency token error
body: <p>Entity Framework Core 2, added a concurrency token property to model</p>
  
  <pre><code>[Timestamp]
  public byte[] Timestamp { get; set; }
  </code></pre>
  
  <p>Controller Edit fails</p>
  
  <pre><code>        [HttpPost]
          [ValidateAntiForgeryToken]
          public async Task&lt;IActionResult&gt; Edit(Guid id, [Bind("Id,Name,Description,IsDeleted,ParentId")] ItemStatus itemStatus)
          {
              if (id != itemStatus.Id)
                  return NotFound();
  
              if (ModelState.IsValid)
              {
                  try
                  {
                      _context.Update(itemStatus);
                      await _context.SaveChangesAsync();
                  }
                  catch (DbUpdateConcurrencyException)
                  {
                      if (!ItemStatusExists(itemStatus.Id))
                      {
                          return NotFound();
                      }
                      else
                      {
                          throw;
                      }
                  }
                  return RedirectToAction(nameof(Index));
              }
  
              ViewData["ParentId"] = new SelectList(_context.ItemStatus, "Id", "Description", itemStatus.ParentId);
              return View(itemStatus);
          }
  </code></pre>
  
  <p>the specific error I am receiving occurs when SaveChangesAsync occurs.  catch pops and when I step in it goes straight to the throw.</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>
    
    <p>Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(int
    commandIndex, int expectedRowsAffected, int rowsAffected)</p>
  </blockquote>
  
  <p>searching for the error message doesn't help.  did find this article but it appears to be no help.</p>
  
  <p><a href="https://docs.microsoft.com/en-us/ef/core/saving/concurrency" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/ef/core/saving/concurrency</a></p>