我有一个“面试”实体,它与“表单提交”实体具有一对一的映射关系,可以说面试实体是主要的一面,映射是:
<class name="Interview">
<id name="Id" column="Id" type="Int64">
<generator class="identity" />
</id>
// other props (snip)....
<one-to-one name="Submission" class="FormSubmission"
cascade="all-delete-orphan" />
</class>
<class name="FormSubmission">
<id name="Id" column="Id" type="Int64">
<generator class="foreign">
<param name="property">Interview</param>
</generator>
</id>
// other props (snip)....
<one-to-one name="Interview" class="Interview"
constrained="true" cascade="none" />
</class>
这两个实体都是聚合的一部分,采访充当聚合根。我正在尝试通过采访实体保存/更新/删除表单提交,因此我已将关联的采访结束映射为 cascade="all-delete-orphan"。例如,我可以像这样创建一个新的 FormSubmission:
myInterview.Submission = new FormSubmission(myInterview);
InterviewRepository.Save(myInterview);
...这工作得很好,FormSubmission 被保存了。但是,我似乎无法删除我正在尝试这样做的 FormSubmission:
myInterview.Submission = null;
InterviewRepository.Save(myInterview);
...但这似乎并没有删除 FormSubmission。我尝试将 null 分配给关联的双方:
myInterview.Submission.Interview = null;
myInterview.Submission = null;
InterviewRepository.Save(myInterview);
我什至尝试在 FormSubmission 端设置 cascade="all-delete-orphan" ,但似乎没有任何效果。我错过了什么?