title: Why does a query generated by Entity Framework take twice as long to run as the same query run directly?
body: <p>I have a simple EF implementation in which I retrieve ~20K records and include two child entities: </p>
  
  <pre><code>using (InsightEntities context = new InsightEntities())
  {
     return context.Accounts
     .Include(x =&gt; x.Division)
     .Include(x =&gt; x.Division.Company)
     .OrderBy(x =&gt; x.ID)
     .AsNoTracking()
     .ToList();
  }
  </code></pre>
  
  <p>When I profile the EF call via SQL Profiler, the duration of the SQL command is ~1.2s, even on subsequent calls.  But if I copy and paste the same SQL that EF is generating and run it directly through SSMS, the duration is half that. </p>
  
  <p>Below is a screenshot of EF calls (red ovals) and direct calls (green ovals):</p>
  
  <p><img src="https://i.stack.imgur.com/c273L.png" alt="enter image description here"></p>
  
  <p>I understand that EF does a lot of work mapping data to objects, interpreting relationships, and so on, but why would the query alone take twice as long as the same query run directly?  Are there changes to the default EF connection string that might optimize the queries?</p>
  
  <p>(I should add that the query itself is completely optimized with indices for all foreign keys.)</p>
  
  <p>Thank you!</p>