【发布时间】:2011-08-07 23:30:26
【问题描述】:
我有一个“Interview”实体,它与“FormSubmission”实体具有一对一的映射关系,可以说,Interview 实体是主要的一面,映射是:
<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>
这两个实体都是聚合的一部分,采访充当聚合根。我正在尝试通过 Interview 实体保存/更新/删除 FormSubmission,因此我已将关联的 Interview 端映射为 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",但似乎没有任何效果。我错过了什么?
【问题讨论】:
标签: c# nhibernate domain-driven-design nhibernate-mapping ddd-repositories