views:

250

answers:

1

I'm so surprise while I'm working in Fluent NHibernate. I got my legacy database that has primary key column name is different from my property in domain model. I'm sure that 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 I really get this mapping in Fluent NHibernate mapping?

+1  A: 

The following 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>
Erik Öjebo