title: Fastest way to fill DataTable from LINQ query using DataContext
body: <p>I am trying to run a linq query but I need the result as a datatable as I am using that to store records from different queries in the same viewstate object.</p>
  
  <p>The 2 versions below compile, but return an empty set. The exact error is <em>"Value cannot be null.
  Parameter name: source"</em>. (and yes I have checked there is data):</p>
  
  <pre><code>MyDatabaseDataContext db = new MyDatabaseDataContext(conn); 
  IEnumerable&lt;DataRow&gt; queryProjects = 
      (from DataRow p in db.STREAM_PROJECTs.AsEnumerable()
      where p.Field&lt;int&gt;("STREAM_ID") == StreamID
      select new
      {
          PROJECT_ID = p.Field&lt;int&gt;("PROJECT_ID"),
          PROJECT_NAME = p.Field&lt;string&gt;("PROJECT_NAME")
      }) as IEnumerable&lt;DataRow&gt;;
  DataTable results = queryProjects.CopyToDataTable&lt;DataRow&gt;();
  </code></pre>
  
  <p>...</p>
  
  <pre><code>//(from p in db.STREAM_PROJECTs.AsEnumerable()
  //where p.STREAM_ID == StreamID
  //select new
  //{
  //    p.PROJECT_NAME,
  //    p.PROJECT_ID
  //}) as IEnumerable&lt;DataRow&gt;;
  </code></pre>
  
  <p>The examples in this <a href="https://stackoverflow.com/questions/16/how-do-i-fill-a-dataset-or-a-datatable-from-a-linq-query-resultset">thread</a> don't seem to work in this situation either. </p>
  
  <p>I guess I could just run a sql query command the old-fashioned way, but isn't linq supposed to be quicker?</p>