如何使用Fluent NHibernate的AutoMap持久性模型“打开”级联保存?
如:
我救了人, ARM 也应该被保存。目前我得到
"object references an unsaved transient instance - save the transient instance before flushing"
public class Person : DomainEntity
{
public virtual Arm LeftArm { get; set; }
}
public class Arm : DomainEntity
{
public virtual int Size { get; set; }
}
我找到了an article on this topic,但它似乎已经过时了。
最佳答案
这适用于新的配置位。有关更多信息,请参见http://fluentnhibernate.wikia.com/wiki/Converting_to_new_style_conventions。
//hanging off of AutoPersistenceModel
.ConventionDiscovery.AddFromAssemblyOf<CascadeAll>()
public class CascadeAll : IHasOneConvention, IHasManyConvention, IReferenceConvention
{
public bool Accept( IOneToOnePart target )
{
return true;
}
public void Apply( IOneToOnePart target )
{
target.Cascade.All();
}
public bool Accept( IOneToManyPart target )
{
return true;
}
public void Apply( IOneToManyPart target )
{
target.Cascade.All();
}
public bool Accept( IManyToOnePart target )
{
return true;
}
public void Apply( IManyToOnePart target )
{
target.Cascade.All();
}
}
关于fluent-nhibernate - 使用Fluent NHibernate自动映射进行级联保存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/586888/