title: LINQ query to Azure SQL database timing out
body: <p>I'm querying my sql database which is in Azure (actually my web app is on Azure as well). </p>
  
  <p>Every time I perform this particular query, there are ever changing errors (e.g. sometimes timeout occurs, sometimes it works perfectly, sometimes it takes extremely long to load). </p>
  
  <p>I have noted that I am using the ToList method here to enumerate the query but I suspect that's why it is degrading. </p>
  
  <p>Is there anyway I can fix this or make it better....<em>or maybe just use native SQL to execute my query?</em>. </p>
  
  <p>I should also note in my webconfig my Database connection timeout is set to 30 seconds. Would this have any performance benefit? </p>
  
  <p>I'm putting the suspect code here: </p>
  
  <pre><code>case null:    
  lstQueryEvents = db.vwTimelines.Where(s =&gt; s.UserID == UserId)
                      .Where(s =&gt; s.blnHide == false)
                      .Where(s =&gt; s.strEmailAddress.Contains(strSearch) || s.strDisplayName.Contains(strSearch) || s.strSubject.Contains(strSearch))
                      .OrderByDescending(s =&gt; s.LatestEventTime)
                      .Take(intNumRecords)
                      .ToList();
                      break;
  </code></pre>
  
  <p>It's basically querying for the 50 records...I don't understand why it's timing out sometimes.</p>