ConfORM Nhibernate OneToMany Cascade

时间:2010-12-10 08:51:48

标签: nhibernate cascade conform

我对Nhibernate ConfORM级联有一些问题。 存在两个实体:

 public class User : BaseEntity
{        
    public User(Role role)
    {            
        this.Role = role;          
    }

    protected User()
    {
    }

    public virtual Role Role { get; protected set; }
}

和角色:

public class Role : BaseEntity
{
    public Role()
    {
        this.Users = new HashedSet<User>();
    }      
    public virtual ISet<User> Users { get; protected set; }
}

级联设置:

 var relationalMapper = new ObjectRelationalMapper();
        relationalMapper.TablePerConcreteClass(domainEntities);
        relationalMapper.Patterns.PoidStrategies.Add(new NativePoidPattern());
        relationalMapper.Cascade<User, Role>(Cascade.Persist);
        relationalMapper.Cascade<Role, User>(Cascade.Persist);

此自动化提供:

<class name="User" table="Users">
<id name="Id" type="Int32">
  <generator class="native" />
</id>
<many-to-one name="Role" column="RoleId" cascade="save-update, persist" />

                                               我想删除没有删除角色的用户。 所有大多数测试都已通过,但这个测试已经过去了:

this.role = new Role();
        this.user = new User(this.role) { Login = "memoryUser", Password = "memoryPass" }.SetIdTo(0);
        role.Users.Add(user);
        this.session.SaveOrUpdate(this.user);
        repo.Delete(this.user);
        var u = repo.GetByName("memoryUser");

        u.Should().Be.Null(); 

错误讯息: 当我尝试删除用户时出现(var u = repo.GetByName(“memoryUser”);)。

  

删除的对象将通过级联删除已删除的对象

重新保存

我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:2)

刷新对DB,Commit transaction的更改?