Fluent NHibernate 一对一没有级联全删除孤儿 [英] Fluent NHibernate one-to-one doesn't have cascade all-delete-orphan
问题描述
我正在将现有的 *.hbm.xml 文件更新为流畅的 ClassMap,并且在我们的映射文件中偶然发现了一个错误,我不知道我正确映射的默认行为.>
映射文件有:
<one-to-one name="LineItemAssembly"class="LineItemAssembly"级联=所有删除孤儿"/>
使用 Fluent 时,我希望它映射到:
HasOne(x => x.LineItemAssembly).Cascade.AllDeleteOrphan();
然而,AllDeleteOrphan() 不是 Cascade 的一个选项(并且正确地如此).我知道这是因为它不是一个选项,而是因为它是映射文件中的错误.使用 Fluent 的等效映射是什么,以便我的 fluent 映射具有与 .hbm.xml 文件完全相同的功能?我认为将 Cascade 排除在 Fluent 映射之外将是默认行为,但我不确定.
最后,我只需要找出问题所在并解决这个问题,而不管默认的流畅行为.在 http://brunoreis 的帮助下.com/tech/fluent-nhibernate-hasone-how-implement-one-to-one-relationship/ 我能够解决这个问题.
我需要添加.Cascade.All().但是,我真正需要的是 LineItemAssembly 类映射中 HasOne 关系之外的 .ForeignKey().
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.
The mapping file has:
<one-to-one name="LineItemAssembly"
class="LineItemAssembly"
cascade="all-delete-orphan" />
When using Fluent, I would expect this to map to:
HasOne<LineItemAssembly>(x => x.LineItemAssembly)
.Cascade.AllDeleteOrphan();
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.
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.
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.
这篇关于Fluent NHibernate 一对一没有级联全删除孤儿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!