【问题标题】:How to delete Nhibernate many-to-many association without deleting referenced objects如何在不删除引用对象的情况下删除 Nhibernate 多对多关联
【发布时间】:2011-05-06 14:20:52
【问题描述】:

大家好

在不删除 NHibernate 中的对象的情况下,我无法删除两个对象之间的关联。我的映射文件:

<?xml version="1.0" encoding="utf-8" ?>

<property name="Name" column="[SiteGroupName]"/>

<many-to-one name="ClientInfo" column="[ClientID]"/>

<set name="internalSites" table="SiteGroupSites" cascade="none" inverse="true">
  <key column="[SiteGroupID]"/>
  <many-to-many class="Site" column="SiteID"/>
</set>

<set name="internalSiteGroups" table="SiteGroupGroups" cascade="none" inverse="true">
  <key column="[SiteGroupID]"/>
  <many-to-many class="SiteGroup" column="ChildSiteGroupID"/>
</set>

所以在我的 C# 代码中,我从 SiteGroup 中删除了一个站点:

siteGroup.Sites.Remove(site);

我不明白的是,当我保存时,它会删除关联和实际站点。我是不是误会了什么?我想要的是从 SiteGroup 中删除站点,而不是完全删除。

我们将不胜感激。

【问题讨论】:

  • Fouche 解决您的问题了吗?

标签: nhibernate many-to-many associations


【解决方案1】:

怎么样

site.Sitegroup = null; //保存

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-02
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    相关资源
    最近更新 更多