title: Entity model .net querying 1 million records from MySQL performance issues
body: <p>I am using an <code>ADO .Net Entity Model</code> for querying a MySQL database. I was very happy about its implementation and usage. I decided to see what would happen if I queried 1 million records and it has serious performance issues, and I don't understand why.</p>
  
  <p>The system hangs for sometime and then I get either</p>
  
  <ul>
  <li>A deadlock exception</li>
  <li>MySQL Exception</li>
  </ul>
  
  <p>My code is as follows::</p>
  
  <pre><code>      try
          {
              // works very fast
              var data = from employees in dataContext.employee_table
                              .Include("employee_type")
                              .Include("employee_status")
                         orderby employees.EMPLOYEE_ID descending                            
                         select employees; 
  
              // This hangs the system and causes some deadlock exception
              IList&lt;employee_table&gt; result = data.ToList&lt;employee_table&gt;(); 
  
              return result;
         }
         catch (Exception ex)
         {
              throw new MyException("Error in fetching all employees", ex);
         }
  </code></pre>
  
  <p>My question is why is ToList() taking such a long time?</p>
  
  <p>Also how can I avoid this exception and what is the ideal way to query a million records?</p>