title: How can I convert a DataTable to an IEnumerable<Dictionary<string, object>>?
body: <p>I'd like to convert a DataTable to an <code>IEnumerable&lt;&gt;</code> of <code>Dictionary&lt;string, object&gt;</code>.  I tried the following LINQ query, </p>
  
  <pre><code>from DataRow row in ds.Tables[0].AsEnumerable()
  let rowDictionary = new Dictionary&lt;string, object&gt;()
  from DataColumn column in row.Table.Columns.Cast&lt;DataColumn&gt;()
  select rowDictionary.Add(column.ColumnName, row[column]).ToArray();
  </code></pre>
  
  <p>but I get the following error:</p>
  
  <pre><code>error CS1943: An expression of type 
  'System.Collections.Generic.IEnumerable&lt;System.Data.DataColumn&gt;' is not 
  allowed in a subsequent from clause in a query expression with source type 
  'System.Data.EnumerableRowCollection&lt;AnonymousType#1&gt;'.  Type inference 
  failed in the call to 'SelectMany'.
  </code></pre>
  
  <p>I know I can brute-force this with a loop, but it seems like something I should be able to do in LINQ.  Thanks in advance for any help!</p>