title: How to assign a nullable int property in an anonymous type in LINQ with a Union?
body: <p>I have two select statements in LINQ with a <code>Union</code>.</p>
  
  <p>A <code>RoleID</code> needs to have a null value in one of the selects. I am getting the error below.</p>
  
  <p>If the <code>RoleID</code> has a value, it works fine. Reports is an EF entity with properties.</p>
  
  <p>It can be anything in this example. Example is simple for illustration purposes.</p>
  
  <p><strong>Code in LinqPad:</strong></p>
  
  <pre><code>var list = Reports.Select(r =&gt; new
      {
          RoleID = 3
      })
      .Union(Reports.Select(r =&gt; new
      {
          RoleID = new Nullable&lt;int&gt;()    &lt;= error
          //RoleID = (int?) null          &lt;= error
          //RoleID = 4                    &lt;= works
      }));
  list.Dump();
  </code></pre>
  
  <p>How do I make it work with a null value and make RoleID of type int?</p>
  
  <p><strong>Error Message:</strong>  </p>
  
  <blockquote>
    <p>'System.Linq.IQueryable' does not contain a definition for 'Union' and the best extension method overload 'System.Linq.ParallelEnumerable.Union(System.Linq.ParallelQuery, System.Collections.Generic.IEnumerable)' has some invalid arguments
    Instance argument: cannot convert from 'System.Linq.IQueryable' to 'System.Linq.ParallelQuery'</p>
  </blockquote>