title: Handling DateTime? in NHibernate/LINQ queries
body: <p>this is a follow-up to question <a href="https://stackoverflow.com/questions/4821560/better-datetime-or-use-defaultdatetime-for-null">Better DateTime? or use default(DateTime) for NULL?</a></p>
  
  <p>I tried to implement a simple query that works with <code>DateTime?</code> with a different example rather than the one of the other question.</p>
  
  <p>In my case I have <code>public virtual DateTime? Expiration</code> property mapped as</p>
  
  <pre><code>&lt;property name="Expiration" not-null="false" type="DateTime" /&gt;
  </code></pre>
  
  <p>Now my LINQ query is the following</p>
  
  <pre><code>return (from product in session.Query&lt;Product&gt;()
                      where
                          !product.Hidden &amp;&amp;
                          (product.Expiration != null ||
                          (product.Expiration.Value - DateTime.Now).TotalDays &lt; 5 &amp;&amp; (product.Expiration.Value - DateTime.Now).TotalDays &gt;= 0)
                      select product).ToList();
  </code></pre>
  
  <p>Query says: pick all products that are not hidden and not expiring in 5 days (&lt;5 verify expired products so I have to add the second check)</p>
  
  <p>I get an exception from ANTLR:</p>
  
  <pre><code>'Antlr.Runtime.NoViableAltException'. [.Where(NHibernate.Linq.NhQueryable`1[Model.Product], Quote((product, ) =&gt; (AndAlso(Not(product.Hidden), OrElse(DateTime.op_Inequality(product.Expiration, NULL), AndAlso(LessThan(DateTime.op_Subtraction(product.Expiration.Value, p2).TotalDays, p3), GreaterThanOrEqual(DateTime.op_Subtraction(product.Expiration.Value, p4).TotalDays, p5)))))), )] 
  </code></pre>
  
  <p>How do I handle a DateTime? in NHibernate 3.0 with LINQ?</p>