Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate 2.* mapping files: how to define nullable DateTime type (DateTime?)?

I know one of the breaking changes with NHibernate 2.* is that the NHibernate.Nullables are no longer supported. Therefore, what do you use in your mapping file to map the nullable DateTime? type? For i.e.:

Understandably doesn't work:

<property name="CreateDate" column="CreateDate" type="DateTime?" not-null="false" />

And no longer supported:

<property name="ModifiedDate" column="ModifiedDate" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" not-null="false"/>

I know it must be so obvious, but I'm not finding it!

Answer is as simple as: NHibernate will reflect over the class in question and discover that the property's reflected type is DateTime? all on its own.

Thanks @Justice!

like image 520
Ted Avatar asked Feb 27 '09 01:02

Ted


1 Answers

<property name="CreatedDate" />
  • NHibernate will reflect over the class in question and discover that the property's reflected type is DateTime? all on its own.
  • NHibernate will assume the column name is by default the same as the property name, unless you tell it otherwise.
  • NHibernate will assume that any property is nullable (not-null="false") unless you tell it otherwise.

If you really want, it should be something like ...

<property name="CreatedDate" type="System.Nullable`1[[System.DateTime, mscorlib]], mscorlib" />
like image 145
yfeldblum Avatar answered Nov 16 '22 12:11

yfeldblum