流畅的 Nhiberhate 和缺失的毫秒
我在当前的项目中使用 Fluent Nhibernate 和 Nhibernate。我需要将时间记录到毫秒。我有这个用于我的映射,
Map(x => x.SystemDateTime)
.CustomType("Timestamp")
.Not.Nullable();
我生成了 hbm.xml 文件,该行如下:
<property name="SystemDateTime" type="Timestamp">
<column name="SystemDateTime" not-null="true" />
</property>
我已阅读这是修复程序,但数据库中的记录没有毫秒。有没有人解决这个问题。我也尝试过 CustomSqlType 。
谢谢
I am using Fluent Nhibernate and Nhibernate for my current project. I need to record the time to the millisecond. I have this for my mapping
Map(x => x.SystemDateTime)
.CustomType("Timestamp")
.Not.Nullable();
I genertaed the hbm.xml files and the line is the following:
<property name="SystemDateTime" type="Timestamp">
<column name="SystemDateTime" not-null="true" />
</property>
I have read this is the fix, but the records in the database do not have the milliseconds. Has anyone solved this issue. And I have tried CustomSqlType also.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我不起作用:
虽然这样做了:
但我不知道为什么:/
This did not work for me:
while this did:
I have no idea why, though :/
重新审视这一点,因为之前的答案稍微不完整。
假设您希望以完整详细信息和毫秒精度存储所有 DateTime 字段,请使用 TIMESTAMP(6)WITH TIME ZONE 作为 SQL 列类型。您需要 FluentNHibernate 的属性约定:
然后将此约定添加到您的 Fluent 配置会话工厂构建代码中:
Revisiting this, as previous answers were slightly incomplete.
Assuming you want all your DateTime fields stored with full details and millisecond precision, use
TIMESTAMP(6) WITH TIME ZONE
as the SQL column type. You'll need a property convention for FluentNHibernate:You then add this convention to your fluent configuration session factory building code:
我们使用与您相同的方法,它确实正确存储了毫秒。如果您不总是这样做,那么您的旧记录就会丢失毫秒。
假设您想为所有 DateTime 字段存储毫秒,您可以使用约定:
您的映射现在可以是:
We use the same approach as you and it does correctly store the milliseconds. If you weren't always doing it that way though your old records will have lost their milliseconds.
Assuming you want to store milliseconds for all of your DateTime fields, you could use a convention:
Your mappings can now just be: