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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:32:19+00:00 2026-05-14T06:32:19+00:00

I have this table structure and would like to map it using Fluent Hibernate

  • 0

I have this table structure and would like to map it using Fluent Hibernate (subclass if possible). I cannot change the structure because the database has too many records and might cause major applications rework. It would be easier if the Id from Party table was a foreign key in person and organization table, but in the particular scenario the database has person and organization key as a foreign key in party table. Any help would be great.

Party table

Id
PersonId
OrganizationId

Person table

Id
FName
LName

Organization table

Id
OrgName
OrgDescription

  • 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-14T06:32:20+00:00Added an answer on May 14, 2026 at 6:32 am

    You can’t map a linking table with the automapping if it contains any fields other than the two ids that make up the composite id. In your case, your Party table has an Id field which breaks the automapping rules because it’s not well-designed (i.e. a composite id shouldn’t have an auto-incrementing id, although we do this for indexing where I work).

    To fix this, you’ll just have to create a ClassMap for Party, and map Id as the Id and reference Person and Organization.

    Then, in your Person and Organization entities, instead of creating a HasManyToMany mapping to Party, you’d create a HasMany to the Party entity.

    Really, what you’re doing is explicitly matching the code to look more like and ERD, whereas the automapping implies many-to-many relationships through a link table only if it contains only a composite primary key.

    This stumped me for three days and I took this route as a “hack”, only to later read this explanation in Fluent NHibernate’s google group a couple of weeks ago.

    I hope that helps, if not I can throw together some code for you.

    See also my post about the same situation.

    edit:

    Here is how this would look at a fairly high level. Remember, you’ll have to initialize your collections in your entity constructors and create setter methods. See Getting Started

    public class Party {
        public virtual int Id { get; set; }
        public virtual Person Person { get; set; }
        public virtual Organization Organization { get; set; }
    }
    public class PartyMap : ClassMap<Party> {
        public PartyMap() {
            Id(x => x.Id);
            References(x => x.Person);
            References(x => x.Organization);
        }
    }
    public class Person {
        public virtual int Id { get; set; }
        public virtual string FName { get; set; }
        public virtual string LName { get; set; }
        public virtual ICollection<Party> Parties { get; set; }
    }
    public class PersonMap : ClassMap<Person> {
        public PersonMap() {
            Id(x => x.Id);
            Map(x => x.FName);
            Map(x => x.LName);
            HasMany(x => x.Parties);
        }
    }
    public class Organization {
        public virtual int Id { get; set; }
        public virtual string OrgName { get; set; }
        public virtual string OrgDescription { get; set; }
        public virtual ICollection<Party> Parties { get; set; }
    }
    public class OrganizationMap : ClassMap<Organization> {
        public OrganizationMap() {
            Id(x => x.Id);
            Map(x => x.OrgName);
            Map(x => x.OrgDescription);
            HasMany(x => x.Parties);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.