nhibernate - 流畅的 Nhiberhate 和缺失的毫秒

标签 nhibernate fluent-nhibernate fluent-nhibernate-mapping

我在当前项目中使用 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。

谢谢

最佳答案

我们使用与您相同的方法,它确实正确存储了毫秒。如果您不总是这样做,尽管您的旧记录将丢失毫秒。

假设您想为所有 DateTime 字段存储毫秒,您可以使用约定:

public class OurPropertyConventions : IPropertyConvention
{
    public void Apply(IPropertyInstance instance)
    {
        Type type = instance.Property.PropertyType;
        if (type == typeof(DateTime) || type == typeof(DateTime?))
            instance.CustomType("Timestamp");
    }
}

您的映射现在可以是:
Map(x => x.SystemDateTime).Not.Nullable();

关于nhibernate - 流畅的 Nhiberhate 和缺失的毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2874057/

相关文章:

Fluent NHibernate 中的 NHibernate 配置属性

asp.net - Web 应用程序在本地工作,但在部署服务器上不工作

c# - NHibernate 一对多无法插入空键

c# - FluentConfigurationException 未处理

view - 映射以查看自定义字段名称 - 一对一关系

nhibernate - Fluent nhibernate 映射嵌套属性 "cannot find getter"

asp.net-mvc - Sql View 的 Fluent Nhibernate 映射

NHibernate 3.2 - 现在所有属性都需要 "set"方法吗?

nhibernate - 使用 QueryOver 删除?

c# - NHibernate QueryOver WithSubQuery WhereAll 子句