只删除表之间的关系,不删除数据
我使用 NHibernate 进行以下类的数据库连接:
Class A
{
public int Id{get;set;}
public List<B> InnerElements{get;set;}
}
Class B
{
public int Id{get;set;}
public string Description{get;set;}
...no reference to the parent
}
在数据库中,我有 As(到 A 类)、Bs(到 B 类)和 AB 表,其中表 AB 有一个自动递增的 id,以及 A 和 B 的 id实体。
这些类的配置文件是:
A 类
...other properties mapped
<bag name="InnerElements" table="ABs" cascade="all" inverse="true">
<key column="AID" />
<many-to-many class="B" column="BID"/>
</bag>
和 B 类,我对 A 类没有任何引用。
当我从 A 类型实体的 InnerElements 中删除 B 元素,并尝试保存/更新修改后的实体时对于 DB,内部 AB 表保持不变。 如何更改(在配置文件或其他方式中)以从内表中删除条目?我不想从数据库中删除任何 A 或 B 条目。
提前致谢, 塔马什
I am using NHibernate for DB connection for the following classes:
Class A
{
public int Id{get;set;}
public List<B> InnerElements{get;set;}
}
Class B
{
public int Id{get;set;}
public string Description{get;set;}
...no reference to the parent
}
and in the DB i have As (to class A), Bs(to class b) and ABs tables where the table ABs has an autoincremented id, and the ids of A and B entities.
The configuration files for the classes are:
Class A
...other properties mapped
<bag name="InnerElements" table="ABs" cascade="all" inverse="true">
<key column="AID" />
<many-to-many class="B" column="BID"/>
</bag>
and in the class B i dont have any refferences to class A.
When I remove an B element from the InnerElements from an entity of type A, and try to Save/Update the modified entity back to the DB, the inner ABs table remains unmodified.
How can I change (in the config files or otherwise) to remove the entry from the inner table ? I dont want to remove any A or B entry from DB.
Thanks in advance,
Tamash
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
删除
inverse="true"
。该属性看起来是复制粘贴的,意味着您正在从另一方处理关系,而在本例中不存在这种关系。Remove the
inverse="true"
. That attribute, which looks copy&pasted, means you are handling the relationship from the other side, which does not exist in this case.