我有一个'采访'实体,它与'FormSubmission'实体有一对一的映射,采访实体是主导的一面,可以这么说,映射是:
<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>
Run Code Online (Sandbox Code Playgroud)
两个实体都是聚合的一部分,采访充当聚合根.我正在尝试通过Interview实体保存/更新/删除FormSubmission,因此我将关联的Interview结束映射为cascade ="all-delete-orphan".例如,我可以像这样创建一个新的FormSubmission:
myInterview.Submission = new FormSubmission(myInterview);
InterviewRepository.Save(myInterview);
Run Code Online (Sandbox Code Playgroud)
...这很好用,FormSubmission保存.但是,我似乎无法删除我正在尝试这样做的FormSubmission:
myInterview.Submission = null;
InterviewRepository.Save(myInterview);
Run Code Online (Sandbox Code Playgroud)
...但这似乎没有删除FormSubmission.我已经尝试将null分配给关联的两端:
myInterview.Submission.Interview = null;
myInterview.Submission = null;
InterviewRepository.Save(myInterview);
Run Code Online (Sandbox Code Playgroud)
我甚至尝试在FormSubmission端设置cascade ="all-delete-orphan",但似乎没有任何效果.我错过了什么?
c# nhibernate domain-driven-design ddd-repositories nhibernate-mapping