9
Greetings,
I'm having problems using a SQL Server 2008 DATE column in C# using Fluent NHibernate.
When I try to update a record that has a value in a non-nullable DATE column prior to 1/1/1753 (the min date for a DATETIME), I'm getting an error saying that it can't insert a NULL into that column. If the value is greater than 1/1/1753, there are no problems and the correct date value is preserved.
Here's my model file:
public class Table1 : model.DBObject
{
public virtual Int32 TestID { get; private set; }
public virtual String Description { get; set; }
public virtual DateTime TestDate { get; set; }
public Table1()
{
}
public static Table1 Load(DBSess sess, Int32 TestID)
{
return (Table1)sess.Session.Get(typeof(Table1), TestID);
}
}
My mapping file:
public class Table1Map : ClassMap<Table1>
{
public Table1Map()
{
Table("[Table1]");
Id(x => x.TestID).GeneratedBy.Identity();
Map(x => x.Description).Not.Nullable();
Map(x => x.TestDate).Not.Nullable().CustomType("date");
}
}
The code being executed:
using (DBSess sess = DBSess.Create())
{
Table1 tbl = dal.Table1.Load(sess, 1);
tbl.Description = String.Format("Updated {0}", DateTime.Now);
tbl.Save(sess);
sess.Commit();
}
The exported NHibernate mappings:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="dal.Table1, dal, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="[Table1]">
<id name="TestID" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="TestID" />
<generator class="identity" />
</id>
<