title: Linq To Data set error System.InvalidCastException: Specified cast is not valid
body: <p>I get the following exception using Linq to data set "System.InvalidCastException: Specified cast is not valid."</p>
  
  <p>The problem is as follows I have a model with two value of type int?. The values in the database are not required so some fields are blank. I have read the table into a data set and now I need to query the data set using the following code. </p>
  
  <pre><code>//model
  public class Model
  {
      // Public Properties
      ...
      ...
      ...
      public int? YearBegin { get; set; }
      public int? YearEnd { get; set; }
  }
  
  //query
  var list = from m in data.Tables["Models"].AsEnumerable()
  select new Model
  {
     // rest of members omitted to simplify
     YearBegin = m.Field&lt;int&gt;("YearBegin"), 
     YearEnd =   m.Field&lt;int&gt;("YearEnd") 
  };
  </code></pre>
  
  <p>I have tried the following none have worked:</p>
  
  <pre><code>m.Field&lt;int?&gt;("YearBegin")
  YearEnd = m.IsNull("YearEnd") ? null, m.Field&lt;int&gt;("YearEnd")
  </code></pre>
  
  <p>Is there another way to check if the field has a value similar to String.IsNullOrEmpty().
  Using string as the type is not a possibility...</p>
  
  <p>Thanks</p>