title: Entity framework performance issue, saveChanges is very slow
body: <p>Recently, I am doing some simple EF work. Very simple,
  first,  </p>
  
  <pre><code>List&lt;Book&gt; books = entity.Books.WHERE(c=&gt;c.processed==false)ToList();  
  then  
      foreach(var book in books)  
      {  
        //DoSomelogic, update some properties,   
      book.ISBN = "ISBN " + randomNumber();  
      book.processed = true;  
      entity.saveChanges(book)  
      }  
  </code></pre>
  
  <p>I put <code>entity.saveChanges</code> within the <code>foreach</code> because it is a large list, around 100k records, and if this record is processed without problem, then flag this record, set book.processed = true, if the process is interrupted by exception, then next time, I don't have to process these good records again.</p>
  
  <p>Everything seems ok to me. It is fast when you process hundreds of records. Then when we move to 100k records, entity.saveChanges is very very slow. around 1-3 seconds per record. Then we keep the entity model, but replace <code>entity.saveChanges</code> with classic <code>SqlHelper.ExecuteNonQuery("update_book", sqlparams)</code>. And it is very fast.</p>
  
  <p>Could anyone tell me why entity framework process that slow? And if I still want to use entity.saveChanges, what is the best way to improve the performance?</p>
  
  <p>Thank you</p>