title: Entity Framework - Performance in count
body: <p>I've a little question about performance with Entity Framework.</p>
  
  <p>Something like </p>
  
  <pre><code>using (MyContext context = new MyContext())
  {
      Document DocObject = context.Document.Find(_id);
      int GroupCount = context.Document.Where(w=&gt;w.Group == DocObject.Group).ToList().Count();
  }
  </code></pre>
  
  <p>takes about 2 seconds in my database (about 30k datasets), while this one</p>
  
  <pre><code>using (MyContext context = new MyContext())
  {
      Document DocObject = context.Document.Find(_id);
      int GroupCount = context.Document.Where(w=&gt;w.Group == DocObject.Group).Count();
  }
  </code></pre>
  
  <p>takes 0,02 seconds.</p>
  
  <p>When my filter for 10 documents had 20 seconds to wait, I checked my code, and changed this to not use <code>ToList()</code> before <code>Count()</code>. </p>
  
  <p>Any ideas why it needs 2 seconds for this line with the <code>ToList()</code>?</p>