1

Fluent NHibernate で作業している間、私はとても驚きました。ドメイン モデルのプロパティとは異なる主キー列名を持つレガシー データベースを取得しました。このマッピング ファイルを使用できると確信しています。

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

しかし、Fluent NHibernate マッピングでこのマッピングを実際に取得するにはどうすればよいでしょうか?

4

1 に答える 1

2

次の 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>
于 2008-12-17T07:35:17.850 に答える