[英]Nhibernate mapping of Table without Entity
我有一個稱為軟件的表和實體
然后我有一個沒有實體的表LinkedSoftware
我正在努力設置我的休眠映射文件,不斷出現映射錯誤。 我沒有運氣就嘗試了以下方法:
<set name="linkedSoftware" access="field" cascade="all-delete-orphan" table="LinkedSoftware">
<many-to-many class="Software" column="BaseSoftwareId" />
<many-to-many class="Software" column="LinkedSoftwareId" />
</set>
<many-to-one name="LinkedSoftware" column="BaseSoftwareId" cascade="save-update" class="Software" />
<many-to-one name="LinkedSoftware" column="LinkedSoftwareId" cascade="save- update" class="Software" />-->
有沒有人能指出我正確的方向。 我試圖用谷歌搜索,但找不到真正的答案。
我認為您也應該使表LinkedSotware
成為實體。 然后嘗試像這樣編寫您的set
:
<set name="LinkedSoftware" table="LinkedSoftware">
<key>
<column name="BaseSoftwareId" />
</key>
<one-to-many class="LinkedSoftware" />
</set>
但是不確定是否全部,因為這會使您僅設置LinkedSoftware
實例,該實例的Software
實例為BaseSoftware
。 對不起,我的英語,希望您能理解。
然后在LinkedSoftware
映射中:
<many-to-one name="BaseSoftware" class="Software">
<column name="BaseSoftwareId" />
</many-to-one>
<many-to-one name="LinkedSoftware" class="Software">
<column name="LinkedSoftwareId" />
</many-to-one>
NHibernate:在同一表中針對同一列的兩個外鍵可以為您提供幫助。 而且我會避免使用多對多方式,我認為這樣會更靈活。 有關多對多說明,請參見Nhibernate:如何用一對多關系表示多對多關系? 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.