Nhibernate Fluent日期时间映射在DB中创建空列

时间:2013-11-16 20:14:39

标签: nhibernate fluent-nhibernate mapping fluent

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

我得到了这个类声明:

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指令。

任何帮助都将非常感激。

1 个答案:

答案 0 :(得分:0)

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

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

相关问题