title: Nhibernate LINQ DateTime.AddDay does not work
body: <p>I need to compare two DateTime properties in a linq query, similar to
  the one below - </p>
  
  <pre class="lang-cs prettyprint-override"><code>var patients = from c in session.Query&lt;Patient&gt;() where c.DateAdded.AddDays(1) &lt; c.AdmitDate select c;
  </code></pre>
  
  <p>when I run the query I get this exception:
  System.NotSupportedException {"System.DateTime AddDays(Double)"}</p>
  
  <p>at
  NHibernate.Linq.Visitors.HqlGeneratorExpressionTreeVisitor.VisitMethodCallExpression(MethodCallExpression
  expression)</p>
  
  <p>I took a look at Fabio's article on
  <a href="http://fabiomaulo.blogspot.com/2010/07/nhibernate-linq-provider-exten" rel="noreferrer">http://fabiomaulo.blogspot.com/2010/07/nhibernate-linq-provider-exten</a>...
  but the treeBuilder doesn't have any functions that are specific to
  DateTime comparisons.</p>
  
  <p>Here is the code for the sample. To run this , install NuGet packages for FluentNhibernate and SQLite. </p>
  
  <pre class="lang-cs prettyprint-override"><code>using System;
  using System.Collections.Generic;
  using System.Data.SQLite;
  using System.IO;
  using System.Linq;
  using System.Text;
  using FluentNHibernate.Cfg;
  using FluentNHibernate.Cfg.Db;
  using FluentNHibernate.Mapping;
  using NHibernate;
  using NHibernate.Cfg;
  using NHibernate.Tool.hbm2ddl;
  using NHibernate.Linq;
  
  namespace ConsoleApplication1
  {
      class Program
      {
              private static Configuration _config;
  
              static void Main(string[] args)
              {
                      var sessionFactory = CreateSessionFactory();
                      using (var session = sessionFactory.OpenSession())
                      {
                              BuildSchema(session);
                              using(var transaction = session.BeginTransaction())
                              {
                                      var foo = new Patient
                                      {
                                              Name = "Foo",
                                              Sex = Gender.Male,
                                              DateAdded = new DateTime(2009, 1, 1),
                                              AdmitDate = new DateTime(2009, 1, 2)
                                      };
                                      var bar = new Patient
                                      {
                                              Name = "Bar",
                                              Sex = Gender.Female,
                                              DateAdded = new DateTime(2009, 1, 1),
                                              AdmitDate = new DateTime(2009, 1, 2)
                                      };
                                      session.SaveOrUpdate(foo);
                                      session.SaveOrUpdate(bar);
                                      transaction.Commit();
                              }
                              session.Flush();
  
                              using (session.BeginTransaction())
                              {
                                      var cats = from c in session.Query&lt;Patient&gt;() where
  c.DateAdded.AddDays(1) &lt; c.AdmitDate select c;
                                      foreach (var cat in cats)
                                      {
                                              Console.WriteLine("patient name {0}, sex    {1}", cat.Name,
  cat.Sex);
                                      }
                              }
                      }
                      Console.ReadKey();
              }
  
              private static ISessionFactory CreateSessionFactory()
              {
                      return Fluently.Configure()
                        .Database(
                              SQLiteConfiguration.Standard.InMemory()
                        )
                        .Mappings(m =&gt;
                              m.FluentMappings.AddFromAssemblyOf&lt;Program&gt;())
                        .ExposeConfiguration(c =&gt; _config = c)
                        .BuildSessionFactory();
              }
  
              private static void BuildSchema(ISession session)
              {
                      new SchemaExport(_config)
                        .Execute(true, true, false, session.Connection, null);
              }
      }
  
      public class PatientMap : ClassMap&lt;Patient&gt;
      {
              public PatientMap()
              {
                      Id(x =&gt; x.Id);
                      Map(x =&gt; x.Name)
                        .Length(16)
                        .Not.Nullable();
                      Map(x =&gt; x.Sex);
                      Map(x =&gt; x.DateAdded);
                      Map(x =&gt; x.AdmitDate);
              }
      }
  
      public class Patient
      {
              public virtual int Id { get; set; }
              public virtual string Name { get; set; }
              public virtual Gender Sex { get; set; }
              public virtual DateTime DateAdded { get; set; }
              public virtual DateTime AdmitDate { get; set; }
      }
  
      public enum Gender
      {
              Male,
              Female
      } 
  </code></pre>
  
  <p>Thanks,
  Vikram </p>