【问题标题】:Nhibernate Fluent datetime mapping creates null column in DBNhibernate Fluent 日期时间映射在 DB 中创建空列
【发布时间】:2013-11-30 03:48:34
【问题描述】:

我真的很难在任何地方找到答案。

我得到了这个类声明:

public class Order
{
   public virtual long Id { get; set; }

   public virtual DateTime OrderDate { get; set; }
}

我创建了一个映射类,在其中使用以下内容映射属性 OrderDate

Map(x => x.OrderDate)
    .CustomSqlType("datetime2")
    .Not.Nullable();

当它被导出到数据库时,它会创建 NULL 列,忽略 Not.Nullable 指令。

任何帮助将不胜感激。

【问题讨论】:

    标签: nhibernate fluent-nhibernate mapping fluent


    【解决方案1】:

    我会说,映射应该是这样的:

    Map(x => x.OrderDate)
        .CustomType("datetime2") // not CustomSqlType
        .Not.Nullable();
    

    如果您使用的是 SQL Server 2008+,请查看此链接以获取有关关系 DB.、CLR 和 NHibernate 类型的更多信息NHibernate and Ms Sql Server 2008: Date, Time, DateTime2 and DateTimeOffset

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 1970-01-01
      • 2012-04-03
      相关资源
      最近更新 更多