Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate multiple primary keys mapping

Tags:

nhibernate

I have a table called "Orderrow". Orderrow has a a compound primary key (CPK) with the following columns: OrderId, ProductId, RowNumber

OrderId and ProductId are also foreign keys refering to the tables Order and Product. The RowNumber is generated in the app.

I was wondering how this is mapped in NHibernate because I can only set 1 id element and 1 generator subelement.

like image 747
Patrick Peters Avatar asked May 12 '09 14:05

Patrick Peters


1 Answers

Here is an example using the composite-id property in a NHibernate mapping file:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain" namespace="Domain.Model">

  <class name="Program" table="program">
    <composite-id>
      <key-property name="Id" column="id"></key-property>
      <key-property name="Prog" column="prog"></key-property>
      <key-property name="Site" column="site"></key-property>
    </composite-id>
    <property name="ActiveDate" column="active_date"/>
    <property name="Year" column="year"/>
  </class>

</hibernate-mapping>
like image 83
Dan Avatar answered Sep 27 '22 22:09

Dan