本文介绍了级联保存与流畅的NHibernate自动映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

如:

我保存人员和手臂也应该保存。目前我得到



  public class Person:DomainEntity 
{
public virtual Arm LeftArm {get;组; }
}

public class Arm:DomainEntity
{
public virtual int Size {get;组; }
}

我找到,但似乎已经过时了。 >

解决方案

这适用于新的配置位。有关详情,请参阅 p>

  //挂断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接受(IManyToOnePart target)
{
return true;
}

public void Apply(IManyToOnePart target)
{
target.Cascade.All();
}
}


How do I "turn on" cascading saves using AutoMap Persistence Model with Fluent NHibernate?

As in:

I Save the Person and the Arm should also be saved. Currently I get

public class Person : DomainEntity
{
  public virtual Arm LeftArm { get; set; }
}

public class Arm : DomainEntity
{
  public virtual int Size { get; set; }
}

I found an article on this topic, but it seems to be outdated.

解决方案

This works with the new configuration bits. For more information, see 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();
    }
}

这篇关于级联保存与流畅的NHibernate自动映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 01:52