如何使用具有Fluent NHibernate的AutoMap持久性模型"打开"级联保存?
如:
我救人,手臂也应该保存.目前我明白了
"对象引用未保存的瞬态实例 - 在刷新之前保存瞬态实例"
public class Person : DomainEntity { public virtual Arm LeftArm { get; set; } } public class Arm : DomainEntity { public virtual int Size { get; set; } }
我发现了一篇关于这个主题的文章,但似乎已经过时了.
这适用于新的配置位.有关更多信息,请参阅http://fluentnhibernate.wikia.com/wiki/Converting_to_new_style_conventions
//hanging off of AutoPersistenceModel .ConventionDiscovery.AddFromAssemblyOf() 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(); } }
更新以与当前版本一起使用:
public class CascadeAll : IHasOneConvention, IHasManyConvention, IReferenceConvention { public void Apply(IOneToOneInstance instance) { instance.Cascade.All(); } public void Apply(IOneToManyCollectionInstance instance) { instance.Cascade.All(); } public void Apply(IManyToOneInstance instance) { instance.Cascade.All(); } }