title: How to convert a data reader to dynamic query results
body: <p>I have a View that typically gets query results from a WebMatrix Query (<code>IEnumerable&lt;dynamic&gt;</code> data type), and displays the results in a table:</p>
  
  <pre><code>@model MySite.Models.Entity
  @foreach(var row in Model.Data)
  {
      &lt;tr&gt;
          @foreach (var column in row.Columns)
          {
              &lt;td&gt;@column&lt;span&gt;:&lt;/span&gt; @row[column]&lt;/td&gt;
          }
      &lt;/tr&gt;
  }
  </code></pre>
  
  <p>Here's my model where I query the database:</p>
  
  <pre><code>public class Entity
  {
      public dynamic Data {get; set; }
      public Entity(String table)
      {
          if (table == "User" || table == "Group)
          {
              WebMatrix.Data.Database db = new WebMatrix.Data.Database();
              db.Open(ConString);
              Data = db.Query("SELECT * FROM " + table);
          }
          else
          {
              using (OdbcConnection con = ne4w OdbcConnection(ConString))
              {
                  OdbcCommand com = new OdbcCommand("Select * From " + table);
                  command.CommandType = System.Data.CommandType.Text;
                  connection.Open();
                  OdbcDataReader reader = command.ExecuteReader();
  </code></pre>
  
  <p>Here's all the different things I've tried from reading various other posts:</p>
  
  <pre><code>                // Atempt 1
                  Data = reader;
                  // Error in view, 'Invalid attempt to call FieldCount when reader is closed' (on 'var row `in` Model.Data')
  
                  // Atempt 2
                  Data = reader.Cast&lt;dynamic&gt;;
                  // Error: 'Cannot convert method group "Cast" to non-delegate type "dynamic". Did you intend to invoke the method?
  
                  // Atempt 3
                  Data = reader.Cast&lt;IEnumerable&lt;dynamic&gt;&gt;;
                  // Error same as Atempt 2
  
                  // Atempt 4
                  Data = reader.Cast&lt;IEnumerable&lt;string&gt;&gt;;
                  // Error same as Atempt 2
              }
          }
      }
  }
  </code></pre>
  
  <p>I'm looking for the best way to get the reader object to a <code>IEnumerable&lt;dynamic&gt;</code> object. </p>
  
  <p><em>Please note this is a simplified example, and while the reason for the two query types is not obvious, they are necessary in my code.</em></p>