Note that there are some explanatory texts on larger screens.

plurals
  1. POPerformance analyze ADO.NET and Entity Framework
    primarykey
    data
    text
    <p>Which one gives better performance? ADO.NET or Entity Framework.</p> <p>These are the two method I want to analyze.</p> <p><strong>ADO.NET Test Method</strong> </p> <pre><code>public void ADOTest() { Stopwatch stopwatch = Stopwatch.StartNew(); using (SqlConnection con = new SqlConnection(connection)) { string Query = "select * from Product "; SqlDataAdapter da = new SqlDataAdapter(Query, con); DataSet ds = new DataSet(); con.Open(); da.Fill(ds); DataView dv = ds.Tables[0].DefaultView; } stopwatch.Stop(); Console.WriteLine("ADO.NET Time Elapsed={0}", stopwatch.Elapsed); } </code></pre> <p><strong>Entity Framework Test Method</strong></p> <pre><code>public void EFTest() { Stopwatch stopwatch = Stopwatch.StartNew(); var list = _OnlineStoreEntities.Products.ToList(); stopwatch.Stop(); Console.WriteLine("Entity Framework Elapsed={0}", stopwatch.Elapsed); } </code></pre> <p><strong>Result in first time execution</strong></p> <p>When I ran this above method in more than 100 times. The average execution time is shown in the image:</p> <p><img src="https://i.stack.imgur.com/8qjBc.jpg" alt="first result"></p> <p>ADO.NET took only 2 milliseconds whether Entity Framework took more than 4 milliseconds. </p> <p><strong>Result in second time execution</strong> </p> <p>When I ran this method again and again in single run. The average execution time between ADO.NET and EF is not much more:</p> <p><img src="https://i.stack.imgur.com/lUEde.jpg" alt="second result"></p> <p><strong>Question</strong></p> <ol> <li>I think EF gives very worst performance in first time execution Then why we use EF?</li> <li>Why EF second time execution was faster than first time execution?</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload