モデル: 1 つのインストールに複数の「コンピュータ システム」を含めることができるモデルがあります。
データベース: テーブル Installations には、名前と説明の 2 つの列があります。テーブル ComputerSystems には、名前、説明、およびインストール ID の 3 つの列があります。
マッピング:
インストール用に次のマッピングがあります。
<?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 クラスは次のとおりです。
public class ComputerSystem { パブリック仮想文字列名 { get; 設定; } public virtual 文字列の説明 { get; 設定; } パブリック仮想インストール インストール { get; 設定; }
}
問題は、ComputerSystem を含むインストールを削除しようとするとエラーが発生することです。エラーは次のとおりです。「削除されたオブジェクトはカスケードによって再保存されます (関連付けから削除されたオブジェクトを削除します)」。誰でも助けることができますか?
よろしく、 セブ