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

  • Home
  • SEARCH
  • 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 8132771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:25:24+00:00 2026-06-06T09:25:24+00:00

I have the following domain objects: public class UserSpecialization : PersonSpecialization, IUserSpecialization { public

  • 0

I have the following domain objects:

public class UserSpecialization : PersonSpecialization, IUserSpecialization
{
    public static readonly string SpecializationNameValue = "User";

    public UserSpecialization()
    {
        Roles = new Collection<IRole>();
    }

    public virtual IEnumerable<IRole> Roles
    {
        get;
        set;
    }
}

public abstract class PersonSpecialization : DomainObjectOfInt32, IPersonSpecialization
{
    public virtual IPerson Person { get; set; }
    public virtual string SpecializationName { get; protected set; }
}

public class Person : DomainObjectOfInt32, IPerson, IAuditable
{
    public Person()
    {
        Specializations = new List<IPersonSpecialization>();
    }

    public virtual IList<IPersonSpecialization> Specializations { get; protected set; }
}

public abstract class Role : DomainObjectOfInt32, IRole, IAuditable
{
    public Role(string roleName)
        : this()
    {
        Name = roleName;
    }
    protected Role()
    {
        AssignedUsers = new Collection<IUserSpecialization>();
    }

    public virtual ICollection<IUserSpecialization> AssignedUsers
    {
        get;
        protected set; }
}

My mapping is as follow:

public class PersonMap : ClassMap<Person>
{
    public PersonMap()
    { 
        Id(x => x.Id).GeneratedBy.Identity();
        HasMany<PersonSpecialization>(c => c.Specializations)
            .Cascade.AllDeleteOrphan();
    }
}

public class RoleMap : ClassMap<Role>
{
    public RoleMap()
    {
        Id(x => x.Id).GeneratedBy.Identity();
        HasManyToMany<UserSpecialization>(x => x.AssignedUsers).Table("UserRole");
        DiscriminateSubClassesOnColumn("Type");
    }
}

public class PersonSpecializationMap : ClassMap<PersonSpecialization>
{
    public PersonSpecializationMap()
    {
        Table("PersonSpecialization");

        Id(c => c.Id).GeneratedBy.Identity();

        DiscriminateSubClassesOnColumn<string>("SpecializationName");

        Map(x => x.SpecializationName).ReadOnly();

        References<Person>(c => c.Person);
    }
}

Now when i select a Person, i get also all his roles in Roles collection. Also when saving a Role, all linked Persons are nicely saved.
But when i save a Person, the linked roles of that Person does not save.

How can i solve this issue?

The mapping of UserSpecialization :

public class UserSpecializationMap : SubclassMap<UserSpecialization>
{
   public UserSpecializationMap()
    {
        Table("User");

        DiscriminatorValue(UserSpecialization.SpecializationNameValue);

        Join("[User]", joined =>
        {
            joined.Map(c => c.UserName, "Username");

            joined.HasManyToMany<Role>(x => x.Roles).Inverse()
                .Table("UserRole");
        });
    }
}
  • 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-06-06T09:25:25+00:00Added an answer on June 6, 2026 at 9:25 am

    you are missing

    public class UserSpecializationMap : SubclassMap<UserSpecialization>
    {
        public UserSpecializationMap()
        {
            Table("PersonSpecialization");
    
            Id(c => c.Id).GeneratedBy.Identity();
    
            DiscriminatorValue("UserSpecialization");
    
            HasManyToMany(x => x.Roles).Cascade.All()...;
        }
    }
    

    btw: i would use a polymorph property for the specializationName then you do not need to specially initialize the property, you can not forget it in a dervied class, it does not take space in the object.

    // base class
    public abstract string SpecializationName { get; }
    
    // dereived class
    public override string SpecializationName { get { return "User"; } }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following domain: public class FileInformation { public String FileName; public String
I have added the following method in my User Domain class String getNameAttribute(){ return
I have the following 2 objects: User and DomainUser User.java: package com.domain; import java.io.Serializable;
I have the following Grails domain class: class Product { String name Float basePrice
I have the following Domain Object: public class DomainClass { public int Id {
I have the following domain object: public class DomainObject<T,TRepo> where T : DomainObject<T> where
I have the following domain object: public class Bank : IEntity { } And
I have the following domain object: public class Data { public virtual int ID
So let's say we have a domain object such as the following public class
If I have the following domain object: public class Customer { public virtual Guid

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.