title: How to Convert var to DataTable?
body: <p>I have following function - </p>
  
  <pre><code>public static DataTable getDetails(PersonContext context)
  {
  DataTable dt = new DataTable();
  IQueryable&lt;Person&gt; query = from p in context.Persons.Include("Employee")
                                                      .Include("Manager")
                                                      .Include("Activity")
                             where p.Activity.IsActive
                             select p;
  var sorted = query.ToArray().OrderByDescending(p=&gt;p.Activity.DateCreated);
  dt = (DataTable)sorted;
  return dt;
  }
  </code></pre>
  
  <p>I can't test it.
  My question is - will this function work. If no what changes should I make in it?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>public static DataTable getDetails(PersonContext context)
  {
  DataTable dt = new DataTable("Details");
  dt.Columns.Add("Name");
  dt.Columns.Add("Department");
  dt.Columns.Add("IsManager");
  IQueryable&lt;Person&gt; query = from p in context.Persons.Include("Employee")
                                                      .Include("Manager")
                                                      .Include("Activity")
                             where p.Activity.IsActive
                             select p;
  var sorted = query.ToArray().OrderByDescending(p=&gt;p.Activity.DateCreated);
  foreach(Person p in sorted)
  {
      dt.Rows.Add(p.Name, p.Employee.Department,p.Manager.IsManager);
  }
      return dt;
  }
  </code></pre>