流利的NHibernate一对一没有级联所有删除的孤儿 [英] Fluent NHibernate one-to-one doesn't have cascade all-delete-orphan

查看:98
本文介绍了流利的NHibernate一对一没有级联所有删除的孤儿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将现有的* .hbm.xml文件更新为流畅的ClassMap,并且偶然发现了我们的映射文件中的一个错误,并且我不知道正确映射此映射的默认行为.

I am in the process of updating the existing *.hbm.xml files into fluent ClassMaps and have stumbled on a mistake in our mapping files, and I don't know the default behavior for me to map this correctly.

映射文件具有:

<one-to-one name="LineItemAssembly" 
            class="LineItemAssembly" 
            cascade="all-delete-orphan" />

使用Fluent时,我希望它可以映射到:

When using Fluent, I would expect this to map to:

HasOne<LineItemAssembly>(x => x.LineItemAssembly)
                        .Cascade.AllDeleteOrphan();

但是,AllDeleteOrphan()不是Cascade的选项(正确的做法是).我了解这是因为它不是选项,而是因为它是映射文件中的错误.用Fluent进行的等效映射是什么,以便我的Fluent映射具有与.hbm.xml文件完全相同的功能?我认为将Cascade排除在Fluent映射之外将是默认行为,但我不确定.

However, AllDeleteOrphan() is not an option off of Cascade (and correctly so). I understand that is because it isn't an option and is because it is an error in the mapping file. What would be the equivalent mapping using Fluent so that my fluent mapping has the exact same functionality as the .hbm.xml file? I would think just leaving Cascade out of the Fluent mapping would be the default behavior, but I just don't know for sure.

推荐答案

最后,无论默认的流畅行为如何,我都只需要找出问题所在并加以解决.借助 http://brunoreis. com/tech/fluent-nhibernate-hasone-how-implementation一对一关系/我能够解决此问题.

In the end, I just needed to figure out what was wrong and fix this, regardless of the default fluent behavior. With the help of http://brunoreis.com/tech/fluent-nhibernate-hasone-how-implement-one-to-one-relationship/ I was able to solve this issue.

我需要添加.Cascade.All().但是,我真正需要的是LineItemAssembly类映射中的HasOne关系中的.ForeignKey().

I needed to add .Cascade.All(). However, what I really needed was a .ForeignKey() off the HasOne relationship in my mapping for the LineItemAssembly class.

这篇关于流利的NHibernate一对一没有级联所有删除的孤儿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆