只删除表之间的关系,不删除数据

发布于 2024-12-21 05:57:53 字数 773 浏览 2 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

篱下浅笙歌 2024-12-28 05:57:53

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文