开发者

ConfORM Nhibernate OneToMany Cascade

开发者_开发问答

I have some problem with Nhibernate ConfORM cascade. Exist two entities:

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

    protected User()
    {
    }

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

and Role:

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

Cascade settings:

 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);

This automapping gives:

<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" />

I want to delete User without delete Role. All most all tests have passed, but this one falls:

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(); 

Error message: It appears when I try to get deleted users (var u = repo.GetByName("memoryUser");).

deleted object would be re-saved by cascade remove deleted object from associations

What should I do to fix this problem?


Flush changes to DB, Commit transaction?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜