Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6182489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:12:26+00:00 2026-05-24T01:12:26+00:00

I have an interesting issue happening with me , i do not know what

  • 0

I have an interesting issue happening with me , i do not know what i m doing wrong, i m using Fluent nHibernate with MVC 3, i got User , Roles , and a UsersinRole table for many to 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 the problem is that when i m deleting any role , it deletes the association of roles with user in UserInRole table and as well as delete all user related to the role i m deleting. same thing happens in inverse if i delete the user.

Does any one know what is the issue ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:12:26+00:00Added an answer on May 24, 2026 at 1:12 am

    You specified .Cascade.All() from User to Role, so of course NHibernate is deleting all Roles when you delete a User. Don’t use .Cascade.All() if that shouldn’t happen.

    You specified .Cascade.SaveUpdate() from Role to User, no User should be deleted when you delete a Role. Are you sure that it deletes the Users and not only the associations to Users?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting issue with HTTPS ports not being handled properly. It is
I have an interesting issue with a gzip/deflate ActionFilterAttribute in ASP.NET MVC 3. If
I have a interesting issue in terms of positioning a div. I am using
I have run into an interesting issue using PHP's date() function. Haven't had any
Here is an interesting issue I noticed when using the Except Operator: I have
Someone please help. I have an interesting issue. I am trying to implement an
I have found an interesting issue in windows which allows me to cause the
I have a rather interesting issue with SVG animation. I am animating along a
I have ran into an interesting issue while trying to create a more usable
I met an interesting issue about C#. I have code like below. List<Func<int>> actions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.