使用nhibernate fluent,您可以像使用hbm一样设置数据类型等吗?

使用nhibernate fluent,您可以像使用hbm一样设置数据类型等吗?,nhibernate,Nhibernate,在我的hbm文件中,我这样做了: <property name="Title" column="title" type="string" length="100" not-null="true"></property> 我假设这将提供更快的数据访问,因为它提供了更多的信息,即长度 fluent是否提供这种行为?是的,fluent NHibernate允许您执行等效映射 要指定字符串的长度,请使用WithLength方法 可以使用ColumnName方法指定列名

在我的hbm文件中,我这样做了:

 <property name="Title" column="title" type="string" length="100" not-null="true"></property>

我假设这将提供更快的数据访问,因为它提供了更多的信息,即长度


fluent是否提供这种行为?

是的,fluent NHibernate允许您执行等效映射

  • 要指定字符串的长度,请使用WithLength方法
  • 可以使用ColumnName方法指定列名
  • 要使属性不可为null,请使用否定属性“not”,后跟方法nullable()
  • 您不需要指定属性的类型,因为它是由Fluent NHibernate推断的
  • 如果要指定数据库中使用的数据类型,请使用CustomSqlTypeIs方法
Fluent NHibernate映射将如下所示:

    Map(x = x.Title)
      .ColumnName("title")
      .WithLengthOf(100) 
      .Not.Nullable();