繁体   English   中英

没有实体的表的休眠映射

[英]Nhibernate mapping of Table without Entity

我有一个称为软件的表和实体


软件

  • ID
  • 串行
  • 名称
  • LinkedSoftware(此字段位于实体中)

然后我有一个没有实体的表LinkedSoftware


LinkedSofware

  • BaseSoftwareId(与Software.Id的关系)
  • LinkedSoftwareId(与Software.Id的关系)

我正在努力设置我的休眠映射文件,不断出现映射错误。 我没有运气就尝试了以下方法:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM