title: Entity framework 5.0 handle optimistic concurrency exception?
body: <p>When handling several potential exceptions during a <code>context.SaveChanges()</code> one of the exceptions is <code>OptimisticConcurrency</code>. Microsoft's documentation on this at <a href="http://msdn.microsoft.com/en-us/library/bb399228.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/bb399228.aspx</a> discusses this for EF 4.x ...</p>
  
  <pre><code>try
  {
      // Try to save changes, which may cause a conflict.
      int num = context.SaveChanges();
      Console.WriteLine("No conflicts. " +
          num.ToString() + " updates saved.");
  }
  catch (OptimisticConcurrencyException)
  {
      // Resolve the concurrency conflict by refreshing the 
      // object context before re-saving changes. 
      context.Refresh(RefreshMode.ClientWins, orders);
  
      // Save changes.
      context.SaveChanges();
      Console.WriteLine("OptimisticConcurrencyException "
      + "handled and changes saved");
  }
  </code></pre>
  
  <p>... but on EF 5.0 (RC), this doesn't seem to work because <code>Refresh()</code> doesn't exist on my EF5, code-first, DbContext derived <code>context</code> class.</p>
  
  <p>I do see <code>context.Entry(context.SalesOrderHeaders).Reload();</code> - but that appears to be a straightup reload-from-db and not a refresh/merge (with policy client wins).</p>
  
  <p>Any ideas how to handle Optimistic concurrency exceptions in EF5? Actually even general pointers on exception handling in SaveChanges() would be nice</p>
  
  <p>Thanks</p>