【问题标题】:FluentNHibernate mapping smalldatetime SQL data typeFluentNHibernate 映射 smalldatetime SQL 数据类型
【发布时间】:2013-10-03 22:09:24
【问题描述】:

我有一个使用smalldatetime SQL 数据类型的旧数据库。这很好地映射到标准DateTime。但是,当我使用 SchemaExport 时,它可以理解地生成具有 datetime 格式的列。我应该在我的映射中使用什么自定义类型,以便生成的列是smalldatetime

   // Does not work as custom type not known       
   Map(x => x.BirthDate).Column("dtBirthDate").Not.Nullable().CustomType("smalldatetime");

【问题讨论】:

    标签: sql nhibernate fluent-nhibernate fluent-nhibernate-mapping smalldatetime


    【解决方案1】:

    您几乎拥有它,而不是 .CustomType 您必须定义 .CustomSqlType

    Map(x => x.BirthDate)
        .Column("dtBirthDate")
        .Not.Nullable()
        .CustomSqlType("smalldatetime")
        .CustomType("datetime")
    

    刚刚测试过,它会创建一个带有 smalldatetime 的数据库列。

    【讨论】:

    • 完美。认为 varchar 有类似 .CustomType("AnsiString") 的等价物。我打算尝试 CustomSqlType,但我很高兴我没有尝试添加 CustomType("datetime")。我假设这也是滚动的方式,即 smallint (CustomerSqlType("smallint").CustomType("int"))。
    • 仅供参考,对于后面的任何人来说,你可以对枚举映射做同样的事情,但需要稍作改动(因为如果你已经在做一个自定义枚举映射器,你就已经定义了自定义类型)。例如,使用字节枚举 Map(x => x.Season).Column("SomeTinyIntColumn").CustomType().CustomSqlType("tinyint")...
    猜你喜欢
    • 2012-06-09
    • 2011-08-25
    • 1970-01-01
    • 2013-11-30
    • 2012-03-14
    • 2012-04-14
    • 2023-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多