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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:50:17+00:00 2026-05-28T03:50:17+00:00

I have the following database structure (which can’t be changed): Users – UserID (int)

  • 0

I have the following database structure (which can’t be changed):

Users
- UserID (int)
- UserType (varchar)
- UserDetailsID (int)

Individual
- IndividualID (int)
...

Organisation
- OrganisationID (int)
...

The UserDetailsID column in the Users table refers to either an Individual or an Organisation, based on the value stored in the UserType column (“individual”, “organisation”).
Definitely not the best database design, but this is what we have to work with for now.

This is the start of our mapping class:

public class UserMap : ClassMap<User>
{
    public UserMap()
    {
        Table("Users");
        LazyLoad();
        Id(x => x.UserID).GeneratedBy.Identity().Column("UserID");

    }
}

What I’m trying to do is to map the UserDetailsID in the User entity to the correct table/entity based on the value in the UserType column.
So it should map to Individual if UserType == “individual”, and to Organisation if UserType == “organisation”.
Is it possible to do this with Fluent NHibernate? And how would that be done?

  • 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-28T03:50:18+00:00Added an answer on May 28, 2026 at 3:50 am

    I came up with one solution myself:

    My entity model looks like this:

    public class User
    {
        public User() { }
    
        public virtual int UserID { get; set; }
        public virtual string UserType { get; set; }
    
        public virtual bool IsIndividual
        {
            get { return UserType == "Individual"; }
        }
    
        public virtual bool IsOrganisation
        {
            get { return UserType == "Organisation"; }
        }
    
        private Individual _individual;
        public virtual Individual Individual 
        {
            get { return (IsIndividual ? _individual : null); }
            set { _individual = value; } 
        }
    
        private Organisation _organisation;
        public virtual Organisation Organisation
        {
            get { return (IsOrganisation ? _organisation : null); }
            set { _organisation = value; }
        }
    }
    

    And then I mapped the UserDetailsID column twice, but using lazy load:

    Map(x => x.UserType).Column("UserType");
    References(x => x.Individual).Column("UserDetailsID").LazyLoad();
    References(x => x.Organisation).Column("UserDetailsID").LazyLoad();
    

    And in the entity it will then call the appropriate reference to Organisation or Individual after checking the UserType first.

    This seems to work fine for me but if anyone has a better solution, please do add your answer.

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

Sidebar

Related Questions

I have two database tables with the following structure: actions: action_id int(11) primary key
I have a table in database which has following structure(data) : +--------------------------+ Organization +--------------------------+
I have a staging database which stores the GEO location as the following structure
I have no control over database schema and have the following (simplified) table structure:
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have the following tables in my database that have a many-to-many relationship, which
I have the following database structure: Event table Id - Guid (PK) Name -
I have a MySQL database with the following table structure: TransactionType : Transaction_Amount, Transaction_ID,
I have an SQL table with basically the following structure: PK (int, primary key),
I have the following XML structure, which is modelling a single concept across multiple

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.