我有3代表這樣的傳統數據庫:
Painting of Tables http://www.bilder-hochladen.net/files/gch8-1.png
該項目表中包含一個計劃中的所有項目。 結構表定義了項目之間的關係。 父項由company
,year
,planId
和表中的parentItem
structure
映射到company
,year
,planId
和表item
的id
限定。
子項目被company
,year
,planId
和表structure
映射childItem
到company
,year
,planId
和表item
的id
限定。自我反思N:使用組合鍵米關係在NHibernate的
我正在尋找一種方法來使用hbm或fluent映射在nhibernate中執行n:m映射。
我想出了:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping namespace="Project.Model" assembly="Project" xmlns="urn:nhibernate-mapping-2.2">
<class name="Item" lazy="true" table="`item`" schema="`dbo`">
<composite-id>
<key-property name="Company" column="`company`" />
<key-property name="Year" column="`year`" />
<key-property name="Planid" column="`planid`" />
<key-property name="ItemId" column="`id`" />
</composite-id>
<!-- Some other properties -->
<set name="Parents" table="`structure`" fetch="select">
<key>
<column name="`company`" />
<column name="`year`" />
<column name="`planid`" />
<column name="`parentItem`" />
</key>
<many-to-many class="Item">
<column name="`company`" />
<column name="`year`" />
<column name="`planid`" />
<column name="`id`" />
</many-to-many>
</set>
<set name="Childs" table="`structure`" fetch="select">
<key>
<column name="`company`" />
<column name="`year`" />
<column name="`planid`" />
<column name="`childItem`" />
</key>
<many-to-many class="Item">
<column name="`company`" />
<column name="`year`" />
<column name="`planid`" />
<column name="`id`" />
</many-to-many>
</set>
<many-to-one name="Plan" class="Plan" not-null="true" fetch="select">
<column name="`company`" />
<column name="`planid`" />
</many-to-one>
</class>
</hibernate-mapping>
然而,錯誤是:Repeated column in mapping …
- 所以我堅持。有什麼建議麼?