【发布时间】:2011-09-28 03:10:12
【问题描述】:
我有以下 NHibernate 文件,但是由于两个答案表中的任何一个都存在外键约束,我不能删除问题。所需的行为是在删除相应的问题并在 Answers 元素上设置级联设置后删除 Answers。
下面是配置文件,大家看看是什么问题
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" namespace="Test.Domain" assembly="Test.Domain" xmlns="urn:nhibernate-mapping-2.2">
<class name="Question" abstract="true">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<discriminator />
<property name="Text" length="500" />
<property name="Note" length="2000" />
<property name="DateRun" />
<many-to-one name="ChoiceType" column="ChoiceTypeId" />
<bag name="Answers" inverse="true" cascade="all,delete-orphan">
<key column="QuestionId" on-delete="cascade" />
<one-to-many class="Answer" />
</bag>
</class>
<class name="Answer" abstract="true">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<many-to-one name="Question" column="QuestionId" />
<many-to-one name="Group" column="GroupId" />
<property name="Comment" />
</class>
<class name="Choice">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="Text" length="500" />
</class>
<class name="ChoiceType">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="Name" />
<property name="Type" />
<list name="Choices" cascade="all,delete-orphan">
<key column="ChoiceTypeId" />
<list-index column="ChoicesPos" />
<one-to-many class="Choice" />
</list>
</class>
<class name="Division">
<id name="Id" type="Int32">
<generator class="hilo" />
</id>
<property name="Name" />
</class>
<union-subclass name="FreeTextAnswer" extends="Answer">
<property name="Text" length="500" />
</union-subclass>
<union-subclass name="MultipleChoiceAnswer" extends="Answer">
<many-to-one name="Choice" column="ChoiceId" />
</union-subclass>
<subclass name="MultipleChoiceQuestion" extends="Question" />
<subclass name="FreeTextQuestion" extends="Question" />
</hibernate-mapping>
【问题讨论】:
标签: nhibernate nhibernate-mapping