Can we have our own primary key column name in Fluent NHibernate?

I am so surprised when I work in Fluent NHibernate. I got my legacy database with a primary key column name different from my property in the domain model. I'm sure I can use this mapping file:

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

      

But how do I actually get this mapping in Fluent NHibernate format?

+1


source to share


1 answer


The following is a Fluent-NHibernate mapping:

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

        Map(x => x.Description);
    }
}

      



generates this XML mapping:

  <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>

      

+1


source







All Articles