title: Optimize the slow query in-memory List using LINQ for retrieving data
body: <p>I have a LINQ query that I am having trouble optimizing. It takes about 6 seconds to run.</p>
  <pre><code>IList&lt;Note&gt; notes;
  data = client.Configuration.Data.OfType&lt;UWData&gt;()
      .Where(s =&gt; s.ShouldDisplay)
      .OrderByDescending(s =&gt; s.Id)
      .ToList()
      .Select(n =&gt; (Note)n)
      .ToList();
  </code></pre>
  <p><code>client.Configuration.Data</code> contains hundreds of thousands of data (100,000 items).
  <code>client.Configuration.Data</code> is a cache, and I am retrieving data from the cache.
  <code>client.Configuration.Data</code> contains 100,000 items, and we have 10 items which is the type of <code>UWData</code>. I want to select the 10 <code>UWData</code>.</p>
  <pre><code>var data = client.Configuration.Data.OfType&lt;UWData&gt;().ToList();
  data = UWData
      .Where(s =&gt; s.ShouldDisplay)
      .OrderByDescending(s =&gt; s.Id)
      .ToList()
      .Select(n =&gt; (Note)n)
      .ToList();
              
  </code></pre>
  <p>The above code also taking a similar time to load.
  Sometimes it takes around 4 seconds to load (exactly 3,356 ms).
  Any ideas on how I could speed this up?</p>