Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Nhibernate-一对一映射,级联所有删除孤立项,不删除孤立项_C#_Nhibernate_Domain Driven Design_Nhibernate Mapping_Ddd Repositories - Fatal编程技术网

C# Nhibernate-一对一映射,级联所有删除孤立项,不删除孤立项

C# Nhibernate-一对一映射,级联所有删除孤立项,不删除孤立项,c#,nhibernate,domain-driven-design,nhibernate-mapping,ddd-repositories,C#,Nhibernate,Domain Driven Design,Nhibernate Mapping,Ddd Repositories,我有一个“面试”实体,它与“表单提交”实体有一对一的映射,面试实体是主导方,可以说,映射是: <class name="Interview"> <id name="Id" column="Id" type="Int64"> <generator class="identity" /> </id> // other props (snip).... <one-to-one name="Subm

我有一个“面试”实体,它与“表单提交”实体有一对一的映射,面试实体是主导方,可以说,映射是:

<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>
…这很好,FormSubmission已保存。但是,我似乎无法删除FormSubmission,我正试图这样做:

myInterview.Submission = new FormSubmission(myInterview);
InterviewRepository.Save(myInterview);
myInterview.Submission = null;
InterviewRepository.Save(myInterview);
…但这似乎并没有删除FormSubmission。我已尝试将null分配给关联的双方:

myInterview.Submission.Interview = null;
myInterview.Submission = null;
InterviewRepository.Save(myInterview);

我甚至尝试在FormSubmission端设置cascade=“all delete orphan”,但似乎没有任何效果。我遗漏了什么?

这可能不是你想要的答案。根据以下问题,主键一对一关联不支持“全部删除孤立项”级联:。即使外键一对一关联也很可能忽略“全部删除孤立项”级联:


编辑:
jchapman使用拦截器(在NH2.x和更高版本中更倾向于使用事件侦听器)来模拟这个功能,这听起来很有趣,但我还不清楚如何实现这样的拦截器/事件侦听器。

aw-man,太糟糕了!我想知道他们不支持的理由是什么?从Fabio Maulo回答的语气判断:“一对一的“全部删除孤儿”?”我猜他认为这种映射是个坏主意,但我想知道为什么?很难说,这是Fabio直接面对的问题:)。无论如何,根据这个问题,它似乎已经在Hibernate 3.5(一年前)中实现了。不知道Hibernate和NHibernate版本是如何关联的…现在标记为已在即将发布的4.1版本中解决。NH-1262问题确实已修复,并在NHibernate 4.1中工作。可以帮助您将其与fluent nhibernate一起使用。
<class name="Interview">
    <id name="Id" column="Id" type="Int64">
        <generator class="identity" />
    </id>

    <property name="Name" />

    <many-to-one name="Submission" unique="true" cascade="all-delete-orphan" />
</class>

<class name="FormSubmission">
    <id name="Id" column="Id" type="Int64">
        <generator class="identity" />
    </id>

    <property name="Name" />

    <one-to-one name="Interview" cascade="all-delete-orphan" property-ref="Submission"  />
</class>