title: How to convert Handsontable data back into C# class
body: <p>I am using an ajax post to send my column headers and data from a handsontable back to an ashx handler.</p>
  
  <pre><code>   $.ajax({
         type: 'POST',
         url: "Scripts/SaveExcelData.ashx",
         contentType: "application/json; charset=utf-8",
         data: JSON.stringify({"columns": hot.getColHeader(), "rows": hot.getData()}),
         success: function (data) {}
     });
  </code></pre>
  
  <p>Currently I am using to following to deserialize the request, but have not been able to successfully come up with anything that converts the rows into an array of DataBaseRow class objects.</p>
  
  <pre><code>var jsonString = String.Empty;
  context.Request.InputStream.Position = 0;
  using (var inputStream = new StreamReader(context.Request.InputStream))
  {
      jsonString = inputStream.ReadToEnd();
      var results = JsonConvert.DeserializeObject&lt;dynamic&gt;(jsonString);
      var columns = results.columns;
      var rows = results.rows;
  
      //use columns here to convert rows into DataBaseRow class
  }
  </code></pre>
  
  <p>columns looks like: <code>{["Col1","Col2","Col3"]}</code><br>
  rows looks like: <code>{[["Val1","Val2","Val3"],["Val1","Val2","Val3"],["Val1","Val2","Val3"]]}</code></p>
  
  <p>How can I do this?</p>
  
  <p><strong>UPDATE</strong><br>
  Instead of trying to convert the dynamic class into the DataBaseRow class, I found I could actually just manually loop through the array values and write them into new instances of the DataBaseRow class.</p>
  
  <pre><code>using (DBEntities edmx = new DBEntities())
  {
      foreach (var row in rows)
      {
          DataBaseRow dbr = new DataBaseRow();
          edmx.DataBaseRow.Add(dbr);
          dbr.LoadedTime = DateTime.Now;
  
          for (int i = 0; i &lt; row.Count; i++)
          {
              string colval = row[i].ToString();
              string colname = columns[i].ToString();
              switch (colname)
              {
                  case "Col1":
                      dbr.DBCol1 = colval;
                      break;
                  case "Col2":
                      dbr.DBCol2 = colval;
                      break;
                  case "Col3":
                      dbr.DBCol3 = colval;
                      break;
              }
          }
      }
      edmx.SaveChanges();
  }
  </code></pre>
  
  <p>This works, but is very slow (see comment for timings). Is there a faster/better way to process this data? (if it matters - I actually have 14 columns that I'm mapping in the switch)</p>