I had a similar problem with these questions:
NHibernate 2. * mapping files: how to determine the null type of DateTime (DateTime?)?
NHibernate will not continue to overflow DateTime SqlDateTime
I am using NHibernate 2.1.2 and FluentNhibernate 1.0.0.636. With NHibernate 2.x, the null value problem DateTime?should be fixed, and I do not need to do anything with my mapping. Accordingly, all my DateTime properties are simply set like this:
public virtual DateTime? CreatedOn { get; set; }
In my database (SQL2008), all DateTime properties are set to null. I have a NHibernate configuration file setup to use the SQL2008 dialect:
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
NHibernate works great for anything that doesn't include DateTime. For reference, here is the exact error I get:
> at
> NHibernate.AdoNet.SqlClientSqlCommandSet.ExecuteNonQuery()</StackTrace><ExceptionString>System.Data.SqlTypes.SqlTypeException:
> SqlDateTime overflow. Must be between
> 1/1/1753 12:00:00 AM and 12/31/9999
> 11:59:59 PM.
If I run SQL Profiler, I can see the last command that NHibernate is trying to execute (it was a very long statement, so I truncated it):
exec sp_executesql N'UPDATE Projects SET Job = @p0, CreatedOn = @p1, .. WHERE (Where Clause), @p0=219221, @p1=NULL
If I execute this statement as a query, SQL persists in this, it does not complain at all!
What's happening?