NHibernate 从 DateTime 变量截断毫秒
NHibernate truncate milliseconds from DateTime variables
我该如何解决这个问题?
NHibernate 从 DateTime 变量中截断毫秒数
DataHoraRecebimento = DateTime.Now;
DataReferencia = new DateTime(2015, 9, 8, 17, 0, 50, 332);
即使我配置了 de LongTimePattern:
这是我在 hbm 上的配置:
版本 3.1.0.4000,
xmlns="urn:nhibernate-mapping-2.2",
MsSql2008方言
<class name="MensagemRecebimento" table="dbo.xxx" lazy="true" dynamic-update="true">
<id name="CodigoRecebimentoMensagem" column="COD_RECB_MSG"><generator class="identity" /></id>
<property name="DataReferencia"><column name="DATA_REF_MSG" sql-type="datetime" not-null="true" /></property>
<property name="DataHoraRecebimento"><column name="DTHR_RECB_MSG" sql-type="datetime" not-null="true" /></property>
</class>
这是保存我的对象的代码
NHibernateSessionHelper.Instance.GetSession().Save(obj);
这里是nHibernate保存后生成的查询结果
您会注意到毫秒为零
NHibernate:
INSERT
INTO
dbo.xxx
(DATA_REF_MSG, DTHR_RECB_MSG)
VALUES
(@p7, @p8);
select
SCOPE_IDENTITY();
@p7 = 08/09/2015 17:00:50.000 [Type: DateTime (0)],
@p8 = 19/08/2016 12:42:48.000 [Type: DateTime (0)]
我得到了答案,我将type="Timestamp"
添加到hbm.xml
<class name="MensagemRecebimento" table="dbo.xxx" lazy="true" dynamic-update="true">
<id name="CodigoRecebimentoMensagem" column="COD_RECB_MSG"> <generator class="identity" /> </id>
<property name="DataReferencia" type="Timestamp"> <column name="DATA_REF_MSG" sql-type="datetime" not-null="true" /> </property>
<property name="DataHoraRecebimento" type="Timestamp"> <column name="DTHR_RECB_MSG" sql-type="datetime" not-null="true" /></property>
</class>
我该如何解决这个问题? NHibernate 从 DateTime 变量中截断毫秒数
DataHoraRecebimento = DateTime.Now;
DataReferencia = new DateTime(2015, 9, 8, 17, 0, 50, 332);
即使我配置了 de LongTimePattern:
这是我在 hbm 上的配置:
版本 3.1.0.4000, xmlns="urn:nhibernate-mapping-2.2", MsSql2008方言
<class name="MensagemRecebimento" table="dbo.xxx" lazy="true" dynamic-update="true">
<id name="CodigoRecebimentoMensagem" column="COD_RECB_MSG"><generator class="identity" /></id>
<property name="DataReferencia"><column name="DATA_REF_MSG" sql-type="datetime" not-null="true" /></property>
<property name="DataHoraRecebimento"><column name="DTHR_RECB_MSG" sql-type="datetime" not-null="true" /></property>
</class>
这是保存我的对象的代码
NHibernateSessionHelper.Instance.GetSession().Save(obj);
这里是nHibernate保存后生成的查询结果 您会注意到毫秒为零
NHibernate:
INSERT
INTO
dbo.xxx
(DATA_REF_MSG, DTHR_RECB_MSG)
VALUES
(@p7, @p8);
select
SCOPE_IDENTITY();
@p7 = 08/09/2015 17:00:50.000 [Type: DateTime (0)],
@p8 = 19/08/2016 12:42:48.000 [Type: DateTime (0)]
我得到了答案,我将type="Timestamp"
添加到hbm.xml
<class name="MensagemRecebimento" table="dbo.xxx" lazy="true" dynamic-update="true">
<id name="CodigoRecebimentoMensagem" column="COD_RECB_MSG"> <generator class="identity" /> </id>
<property name="DataReferencia" type="Timestamp"> <column name="DATA_REF_MSG" sql-type="datetime" not-null="true" /> </property>
<property name="DataHoraRecebimento" type="Timestamp"> <column name="DTHR_RECB_MSG" sql-type="datetime" not-null="true" /></property>
</class>