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 6878641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:44:56+00:00 2026-05-27T04:44:56+00:00

I’m using ActiveRecord with NHibernate on the backend. I’ve set up a mapping for

  • 0

I’m using ActiveRecord with NHibernate on the backend. I’ve set up a mapping for Users; I can create/retrieve/register users without any issues.

I now want to add an association called Role to my users (many users per role). I’ve created the appropriate Role class, tables, data, etc. and everything seems to be working on that end as well.

The problem is that when I save a user and associate a Role, that association does not persist to the database.

I’ve added a RoleId (int16) column to the aspnet_Users table to match the Role table’s Id (int16) column. I’ve tried using Save and SaveAndFlush without success.

Here’s some code:

Role superUser = Role.First(r => r.name == "Super User");
User me = User.First(r => r.UserName == myUserName);
me.Role = superUser;
me.Save(); // Or: SaveAndFlush

When debugging, I can see the association on the objects when they’re saved (i.e. me.Role is not null and has the right attributes/properties/etc.) However, when I look at the database, the RoleId value for that user is still NULL. (SaveAndFlush doesn’t make a difference.)

What am I missing?

I’ve read somewhere on SO that extending the users table is usually done by adding another table and linking the two by a foreign key; I assume the classes would then use inheritance by composition for the new ExtendedUser class. Assuming I don’t want to go that route, why isn’t this working? Is it because of the specific ASP.NET MVC stored procedures et. all?

Some relevant mapping:

   [ActiveRecord("aspnet_Users", Mutable = false)]
    public class User : ActiveRecordLinqBase<User>
    {
        [PrimaryKey(PrimaryKeyType.Assigned)]
        public Guid UserId { get; set; }

        // ...

        [BelongsTo("RoleId", Cascade = CascadeEnum.SaveUpdate)]
        public Role Role { get; set; }
    }

    [ActiveRecord]
    public class Role : ActiveRecordLinqBase<Role>
    {
        [PrimaryKey]
        public int Id { get; set; }

        // ...

        [HasMany(Inverse = true)]
        public IList<User> Users { get; set; }

        [Property]
        public string Name { get; set; }
    }
  • 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-27T04:44:57+00:00Added an answer on May 27, 2026 at 4:44 am

    Edit: mutable=”false” – this clearly stands that entity is read only, which is the source of your problem.

    Immutable classes, mutable=”false”, may not be updated or deleted by the application. This allows NHibernate to make some minor
    performance optimizations.

    Also:
    I believe that you need to have cascading defined. You are not saving just the entity itself but also reference to other entity. Use attributes, fluent config or hbml to define this the way you need. Here are the cascading options:

    Here is what each cascade option means:

    • none – do not do any cascades, let the users handles them by
      themselves.
    • save-update – when the object is saved/updated, check the assoications and save/update any object that require it (including
      save/update the assoications in many-to-many scenario).
    • delete – when the object is deleted, delete all the objects in the assoication.
      delete-orphan – when the object is deleted, delete all the objects in the assoication. In addition to that, when an object is
      removed from the assoication and not assoicated with another object
      (orphaned), also delete it.
    • all – when an object is save/update/delete, check the assoications and save/update/delete all the objects found.
    • all-delete-orphan – when an object is save/update/delete, check the assoications and save/update/delete all the objects found. In additional to that, when an object is removed from the assoication and not assoicated with another object (orphaned), also delete it.

    You may want to read this article.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.