0
型號: 我,其中一個安裝可以包含多個「計算機系統」的典範。NHibernate的:刪除錯誤
數據庫: 表安裝有兩列名稱和說明。 表ComputerSystems有三個columsn名稱,描述和InstallationId。
映射:
我有安裝下面的映射:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="myProgram.Core" namespace="myProgram">
<class name="Installation" table="Installations" lazy="true">
<id name="Id" column="Id" type="int">
<generator class="native" />
</id>
<property name="Name" column="Name" type="string" not-null="true" />
<property name="Description" column="Description" type="string" />
<bag name="ComputerSystems" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="InstallationId" />
<one-to-many class="ComputerSystem" />
</bag>
</class>
</hibernate-mapping>
我有COMPUTERSYSTEM以下映射:
<?xml version="1.0" encoding="utf-8"?>
<id name="Id" column="ID" type="int">
<generator class="native" />
</id>
<property name="Name" column="Name" type="string" not-null="true" />
<property name="Description" column="Description" type="string" />
<many-to-one name="Installation" column="InstallationID" cascade="save-update" not-null="true" />
類:
的安裝類型:
public class Installation
{
public virtual String Description { get; set; }
public virtual String Name { get; set; }
public virtual IList<ComputerSystem> ComputerSystems
{
get
{
if (_computerSystemItems== null)
{
lock (this)
{
if (_computerSystemItems== null)
_computerSystemItems= new List<ComputerSystem>();
}
}
return _computerSystemItems;
}
set
{
_computerSystemItems= value;
}
}
protected IList<ComputerSystem> _computerSystemItems;
public Installation()
{
Description = "";
Name= "";
}
}
的COMPUTERSYSTEM類是:
公共類COMPUTERSYSTEM { 公共虛擬字符串名稱{得到;組; } public virtual String Description {get;組; } 公共虛擬安裝安裝{獲得;組; }
}
問題是當試圖刪除包含ComputerSystem的安裝時出現錯誤。錯誤是:「刪除的對象將被級聯重新保存(從關聯中刪除刪除的對象)」。誰能幫忙?
問候, 勒布