Reputation: 6290
I'm having a similar problem to these questions:
NHibernate 2.* mapping files: how to define nullable DateTime type (DateTime?)?
NHibernate won't persist DateTime SqlDateTime overflow
I'm using NHibernate 2.1.2 and FluentNhibernate 1.0.0.636. With NHibernate 2.x the nullable DateTime?
issue should be fixed and I shouldn't have to do anything special with my mapping. Accordingly, all my DateTime properties are simply set like so:
public virtual DateTime? CreatedOn { get; set; }
In my database (SQL2008), all DateTime properties are set to allow null. I have my NHibernate config file setup to use the SQL2008 dialect:
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
NHibernate works fine for anything that does not include a DateTime. For reference, here's the exact error I'm receiving:
> 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 attempts to execute (this was a very long statement, so I've 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 it fine, doesn't complain at all!
What's going on?
Upvotes: 5
Views: 1688
Reputation: 15237
I had this same issue. At first I thought I fixed it by switching my sql type from a nullable date to a nullable datetime. However, that was a mirage. The root cause was a cascading update on another newly added table.
This would have been quickly resolved if everyone (but especially MS) threw more descriptive errors. Cest la vie.
Upvotes: 0
Reputation: 6290
I don't know why, but this works here. Unlike the example in the link, mine are DateTime?
so .... I do not know why it works, but it does.
Upvotes: 0
Reputation: 49261
Your DateTime properties are probably set to DateTime.MinValue (1/1/0001) instead of null or a value in the valid range for a DateTime column.
Upvotes: 1