title: Use EF to delete a record by id, if id does not exist, an exception is thrown
body: <p>The code looks like this:</p>
  
  <pre><code>try
  {
      Student stu = new Student() { ID = id };
      db.Entry(stu).State = EntityState.Deleted;
  
      int result = db.SaveChanges();
  }
  catch (DataException e)
  {
  
  }
  </code></pre>
  
  <p>The exception is:</p>
  
  <blockquote>
    <p>Store update, insert, or delete statement affected an unexpected
    number of rows (0). Entities may have been modified or deleted since
    entities were loaded. See
    <a href="http://go.microsoft.com/fwlink/?LinkId=472540" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/?LinkId=472540</a> for information on
    understanding and handling optimistic concurrency exceptions.</p>
  </blockquote>
  
  <p>...but I don't want to get an exception, I want get the number of affected rows, like <code>0</code>.</p>