【问题标题】:Could we have custom name of the primary key column in Fluent NHibernate?我们可以在 Fluent NHibernate 中自定义主键列的名称吗?
【发布时间】:2008-12-17 06:22:36
【问题描述】:

当我在 Fluent NHibernate 中工作时,我感到非常惊讶。我得到了具有主键列名称的旧数据库与域模型中的属性不同。我确定我可以使用这个映射文件:

<class name="Person">
  <id name="Id" column="CommentId">
      <generator class="native"/>
  </id>
  <property name="Description" type="String" />
</class>

但是我如何真正在 Fluent NHibernate 映射中获得这种映射?

【问题讨论】:

    标签: .net nhibernate fluent-nhibernate nhibernate-mapping


    【解决方案1】:

    以下 Fluent-NHibernate 映射:

    public class PersonMap : ClassMap<Person>
    {
        public PersonMap()
        {
            Id(x => x.Id, "CommentId")
                .GeneratedBy.Native();
    
            Map(x => x.Description);
        }
    }
    

    生成此 XML 映射:

      <class name="Person" table="[Person]" xmlns="urn:nhibernate-mapping-2.2">
        <id name="Id" column="CommentId" type="Int32">
          <generator class="native" />
        </id>
        <property name="Description" column="Description" length="100" type="String">
          <column name="Description" />
        </property>
      </class>
    

    【讨论】:

      猜你喜欢
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 2010-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多