asp.net mvc - Fluent nHibernate Issue in Many to Many Mappings -


i have interesting issue happening me , not know m doing wrong, m using fluent nhibernate mvc 3, got user , roles , , usersinrole table many many relationship.

user mapping:

id(user => user.userid).generatedby.guid();         map(user => user.username).not.nullable();         map(user => user.password).not.nullable();         map(user => user.fullname).not.nullable();         map(user => user.email).not.nullable();         map(user => user.isactive).not.nullable();         map(user => user.creationdate).not.nullable();          hasmanytomany<role>(x => x.roles).table("tbluserinroles")                                             .parentkeycolumn("userid")                                             .childkeycolumn("roleid")                                             .cascade.all()                                             .not.lazyload(); 

roles mapping:

 id(role => role.roleid).generatedby.identity();         map(role => role.rolename).not.nullable();         map(role => role.isactive).not.nullable();         map(role => role.description).not.nullable();          hasmanytomany<user>(x => x.users)             .table("tbluserinroles")             .parentkeycolumn("roleid")             .childkeycolumn("userid")             .cascade.saveupdate()             .inverse()             .not.lazyload(); 

user entity:

public virtual guid userid { get; set; }     public virtual string username { get; set; }     public virtual string password { get; set; }     public virtual string fullname { get; set; }     public virtual string email { get; set; }     public virtual timespan lastlogin { get; set; }     public virtual bool isactive { get; set; }     public virtual datetime creationdate { get; set; }     public virtual ilist<role> roles { get; set; }      public user()     {         roles = new list<role>();      }     public virtual void addroles(role role)     {         role.users.add(this);         roles.add(role);     } 

role entity:

 public virtual string rolename { get; set; }      public virtual bool isactive { get; set; }     public virtual string description { get; set; }     public virtual ilist<user> users { get; set; }     public virtual ilist<role> roles { get; set; }      public role()     {         users = new list<user>();     } 

now problem when m deleting role , deletes association of roles user in userinrole table , delete user related role m deleting. same thing happens in inverse if delete user.

does 1 know issue ?

you specified .cascade.all() user role, of course nhibernate deleting roles when delete user. don't use .cascade.all() if shouldn't happen.

you specified .cascade.saveupdate() role user, no user should deleted when delete role. sure deletes users , not associations users?


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -