title: Linq to DataTable - Cannot cast DBNull
body: <p>New to Linq, so apologies if this is basic. This query is throwing up the error {"Cannot cast DBNull.Value to type 'System.Int64'. Please use a nullable type."} when I enumerate the results. </p>
  
  <pre><code>    private void AddLevels(long rootid)
      {
          var results = from row in data.AsEnumerable()
                        where row.Field&lt;long&gt;("ParentID") == rootid
                        select row;
  
          foreach (DataRow row in results)
          {
              //do stuff
          }
  
      }
  </code></pre>
  
  <p>The column ParentID does accept nulls - do I need to handle these separately?</p>
  
  <p><strong>EDIT2:</strong> Actual solution below that still uses Linq.</p>
  
  <p><strong>EDIT:</strong> I solved this by scrapping Linq and just using a DataTable.Select statement instead. If anyone's got input on the performance difference I'd be interested. </p>