title: How to get IEnumerable(Of DataRow) From DataTable query
body: <p>All the examples I have found of complex grouping of <code>DataTable</code> results that use linq query commands look to have no problems getting an <code>IEnumerable(Of DataRow)</code> object as the result.  </p>
  
  <p>However I seem to only get a <code>AnonymousType Enumerator</code> return that I cannot cast to <code>DataTable</code>.
  <br>I have workarounds, but would prefer to convert the results to a <code>DataTable</code>, as it looks possible and I may be doing something wrong.</p>
  
  <p>It's a simple table with Many <code>ClientID</code> and <code>ClientName</code> columns and other columns with login timestamps.   </p>
  
  <pre><code>Dim dtMatrix As DataTable = New DataTable()
  </code></pre>
  
  <p>... (populate DataTable)</p>
  
  <pre><code>Dim qClients = From row In dtMatrix 
    Group row By client = New With {Key .ClientID = row("ClientID"), Key .ClientName = row("ClientName")} Into Group 
    Select New With {Key .ClientID = client.ClientID, Key .ClientName = client.ClientName}
  </code></pre>
  
  <p>This returns the generic Enumerator result, however</p>
  
  <pre><code>Dim qClients As IEnumerable(Of DataRow) = From row In dtMatrix 
    Group row By client = New With {Key .ClientID = row("ClientID"), Key .ClientName = row("ClientName")} Into Group 
    Select New With {Key .ClientID = client.ClientID, Key .ClientName = client.ClientName}
  </code></pre>
  
  <p>Throws an exception</p>
  
  <blockquote>
    <p>Unable to cast object of type... to type
    'System.Collections.Generic.IEnumerable`1[System.Data.DataRow]'.</p>
  </blockquote>
  
  <p>I will be happy to paste the whole error message if it will add more clarity.</p>
  
  <p>My base assumption is that the <code>DataTable</code> should allow the cast to occur inherently as it is the object being queried.  However this does not seem to be the case.  Have I constructed my query incorrectly?  (Framework 4.6.2)</p>