title: How to update record using Entity Framework 6?
body: <p>I am trying to update a record using EF6. First finding the record, if it exists, update.
  Here is my code:</p>
  <pre><code>var book = new Model.Book
  {
      BookNumber =  _book.BookNumber,
      BookName = _book.BookName,
      BookTitle = _book.BookTitle,
  };
  using (var db = new MyContextDB())
  {
      var result = db.Books.SingleOrDefault(b =&gt; b.BookNumber == bookNumber);
      if (result != null)
      {
          try
          {
              db.Books.Attach(book);
              db.Entry(book).State = EntityState.Modified;
              db.SaveChanges();
          }
          catch (Exception ex)
          {
              throw;
          }
      }
  }
  </code></pre>
  <p>Every time I try to update the record using the above code, I am getting this error:</p>
  <blockquote>
  <p>{System.Data.Entity.Infrastructure.DbUpdateConcurrencyException: Store
  update, insert, or delete statement affected an unexpected number of
  rows (0). Entities may have been modified or deleted since entities
  were loaded. Refresh ObjectStateManager entries</p>
  </blockquote>