title: DbContext.ChangeTracker.HasChanges is very slow
body: <p>My application uses Entity Framework 6.1.0 and <code>DbContext</code> API.</p>
  
  <p>It's a some kind of CAD system, and it is intended to edit some engineering documents. To detect the fact of changes in the document, I'm using <code>DbContext.ChangeTracker.HasChanges</code>. </p>
  
  <p>When document has large amount of data (approximately 20-25 thousands of entities), <code>DbContext.ChangeTracker.HasChanges</code> is running <strong>very slow</strong>. Since this code is used to enable/disable "Save" command, it executes rather frequently from UI thread. This, in turn, hits application performance.</p>
  
  <p>I've re-written this fragment:</p>
  
  <pre><code>    private Lazy&lt;DbContext&gt; context;
  
      public bool HasChanges
      {
          get
          {
              if (!context.IsValueCreated)
              {
                  return false;
              }
  
              return context.Value.ChangeTracker.HasChanges();
          }
      }
  </code></pre>
  
  <p>to this one:</p>
  
  <pre><code>    public bool HasChanges
      {
          get
          {
              if (!context.IsValueCreated)
              {
                  return false;
              }
  
              var objectStateManager = ((IObjectContextAdapter)context.Value).ObjectContext.ObjectStateManager;
  
              return
                  objectStateManager.GetObjectStateEntries(EntityState.Added).Any() ||
                  objectStateManager.GetObjectStateEntries(EntityState.Deleted).Any() ||
                  objectStateManager.GetObjectStateEntries(EntityState.Modified).Any();
          }
      }
  </code></pre>
  
  <p>and (it's a miracle!) everything works extremely fast.</p>
  
  <p>Looks like <code>DbChangeTracker.HasChanges</code> implementation isn't optimal.
  Am I missing something?</p>