NHibernate 2.* 映射文件:如何定义可为空的 DateTime 类型(DateTime?)? [英] NHibernate 2.* mapping files: how to define nullable DateTime type (DateTime?)?
问题描述
我知道 NHibernate 2.* 的重大变化之一是不再支持 NHibernate.Nullables.因此,您在映射文件中使用什么来映射可为空的 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.:
可以理解不起作用:
<property name="CreateDate" column="CreateDate" type="DateTime?" not-null="false" />
不再支持:
<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!
答案很简单:NHibernate 将反射有问题的类并发现该属性的反射类型是 DateTime?一切都靠自己.
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.
谢谢@Justice!
Thanks @Justice!
推荐答案
<property name="CreatedDate" />
- NHibernate 将反射有问题的类,并发现该属性的反射类型是
DateTime?
完全独立的. - NHibernate 将默认列名与属性名相同,除非您另有说明.
- NHibernate 将假定任何属性都是可为空的 (
not-null="false"
),除非您另有说明. - 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" />
这篇关于NHibernate 2.* 映射文件:如何定义可为空的 DateTime 类型(DateTime?)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!