title: Type cast a base list to derived list within a LINQ query
body: <p>So let me go through the scenario of what I'm trying to do.
  I have four classes(representing documents in my business), with a common base class, 'DocumentBaseClass'.
  This base class contains a property &quot;type&quot; among 2-3 other properties.
  There's a set of data in cosmos db, that contains all the data against these models.
  I need to retrieve all of it, with only one trip to DB and then store in SQL DB in their tables(of their respective models)
  Therefore, I am applying a linq query on the entire result received.
  The linq query filters all the data where the type is of the specific document and since this is of the base type and I need the derived class for the data to be added to their table, I am type casting it to that specific class.
  I have yet to test it, that is another long process.</p>
  <p>Now my questions are,
  1.Is my linq query efficient?
  2.And is the casting correct?
  3.Is there any way to make is more efficient?</p>
  <pre><code>Expression&lt;Func&lt;DocumentBaseClass,bool&gt;&gt; predicate = x =&gt; x.id == id; // the id passed to the function
  var result = await _cosmosDBClient.GetItemsAsync(predicate);
  var derivedClassARecords = result.Data.Where(cb =&gt; cb.Type==&quot;DerivedClassA&quot;).Cast&lt;DerivedClassA&gt;();
  var derivedClassBRecords = result.Data.Where(cb =&gt; cb.Type==&quot;DerivedClassB&quot;).Cast&lt;DerivedClassB&gt;();
  </code></pre>
  <p>After this a service is called for each type that will add data to their respective tables.</p>
  <pre><code>foreach (var item in derivedClassARecords)
  {
      _derivedClassBService.Process(item);
  }
  
  foreach (var item in derivedClassBRecords)
  {
      _derivedClassBService.Process(item);
  }
  </code></pre>