2

我想为 NIBerate 配置一个约定,以允许级联保存或更新和合并,但不允许删除。我找不到如何执行此操作,因为 Cascade.SaveOrUpdate() 或 Cascade.Merge() 返回无效。并调用一种方法取消了先例。

这是我的试验:

1)级联将用于 SaveUpdate :

 public class CascadeAllConvention : IHasOneConvention, IHasManyConvention, IReferenceConvention
    {
        public void Apply(IOneToOneInstance instance)
        {
            instance.Cascade.Merge();
            instance.Cascade.SaveUpdate();
        }

        public void Apply(IOneToManyCollectionInstance instance)
        {
            instance.Cascade.Merge();
            instance.Cascade.SaveUpdate();

        }

        public void Apply(IManyToOneInstance instance)
        {
            instance.Cascade.Merge();
            instance.Cascade.SaveUpdate();
        }
    }

2)级联将用于合并:

 public class CascadeAllConvention : IHasOneConvention, IHasManyConvention, IReferenceConvention
    {
        public void Apply(IOneToOneInstance instance)
        {
            instance.Cascade.SaveUpdate();
            instance.Cascade.Merge();
        }

        public void Apply(IOneToManyCollectionInstance instance)
        {
            instance.Cascade.SaveUpdate();
            instance.Cascade.Merge();

        }

        public void Apply(IManyToOneInstance instance)
        {
            instance.Cascade.SaveUpdate();
            instance.Cascade.Merge();
        }
    }

3) 级联将被停用:

 public class CascadeAllConvention : IHasOneConvention, IHasManyConvention, IReferenceConvention
    {
        public void Apply(IOneToOneInstance instance)
        {
            instance.Cascade.All();
            instance.Cascade.Not.Delete();
        }

        public void Apply(IOneToManyCollectionInstance instance)
        {
            instance.Cascade.All();
            instance.Cascade.Not.Delete();

        }

        public void Apply(IManyToOneInstance instance)
        {
            instance.Cascade.All();
            instance.Cascade.Not.Delete();
        }
    }
4

0 回答 0