title: Why Entity Framework performs faster than Dapper in direct select statement
body: <p>I'm new to using ORM in dealing with database, Currently I'm making a new project and I have to decide if i'll use Entity Framework or Dapper. I read many articles which says that Dapper is faster than Entity Framework.</p>
  
  <p>So I made 2 simple prototype projects one using Dapper and the other uses Entity Framework with one function to get all the rows from one table.
  The table schema as the following picture</p>
  
  <p><img src="https://i.stack.imgur.com/MCfHX.png" alt="Table Schema"></p>
  
  <p>and the code for both projects as the following</p>
  
  <p>for Dapper project</p>
  
  <pre><code>System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
  sw.Start();
  IEnumerable&lt;Emp&gt; emplist = cn.Query&lt;Emp&gt;(@"Select * From Employees");
  sw.Stop();
  MessageBox.Show(sw.ElapsedMilliseconds.ToString());
  </code></pre>
  
  <p>for Entity Framework Project</p>
  
  <pre><code>System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
  sw.Start();
  IEnumerable&lt;Employee&gt; emplist = hrctx.Employees.ToList();
  sw.Stop();
  MessageBox.Show(sw.ElapsedMilliseconds.ToString());
  </code></pre>
  
  <p>after trying the above code many times only the first time I run the project the dapper code will be faster and after this first time always I get better results from entity framework project
  I tried also the following statement on the entity framework project to stop the lazy loading</p>
  
  <pre><code>hrctx.Configuration.LazyLoadingEnabled = false;
  </code></pre>
  
  <p>but still the same EF performes faster except for the first time.</p>
  
  <p>Can any one give me explanation or guidance on what makes EF faster in this sample although all the articles on the web says the opposite</p>
  
  <p><strong>Update</strong></p>
  
  <p>I've changed the line of code in the entity sample to be</p>
  
  <pre><code>IEnumerable&lt;Employee&gt; emplist = hrctx.Employees.AsNoTracking().ToList();
  </code></pre>
  
  <p>using the <strong>AsNoTracking</strong> as mentioned in some articles stops the entity framework caching and after stopping the caching the dapper sample is performing better, (but not a very big difference)</p>