NHibernate 2. *映射文件:如何定义可空的DateTime类型(DateTime?)? [英] NHibernate 2.* mapping files: how to define nullable DateTime type (DateTime?)?
问题描述
可以理解不起作用:
property name =CreateDatecolumn =CreateDatetype =DateTime? not-null =false/>
不再支持:
< property name =ModifiedDatecolumn =ModifiedDatetype =Nullables.NHibernate.NullableDateTimeType,Nullables.NHibernatenot-null =false/>
我知道这一定很明显,但我没有找到它!
答案很简单:
NHibernate会反映所讨论的类,并发现该属性的反映类型是DateTime?所有的都是自己的。
感谢@Justice!
< property name =CreatedDate/>
- NHibernate会反映相关课程,发现该物业的反映类型是
DateTime?
全部自己。 - NHibernate将假定列名与默认情况下属性名称相同,除非否则你会告诉它。
- NHibernate会假定任何属性都为空(
not-null =false
)除非你告诉
如果你真的想要,应该是这样的...
< property name =CreatedDatetype =System.Nullable`1 [[System.DateTime,mscorlib]],mscorlib/>
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!
<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" />
这篇关于NHibernate 2. *映射文件:如何定义可空的DateTime类型(DateTime?)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!