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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:31:14+00:00 2026-05-21T16:31:14+00:00

I’ve got this question that’s been bugging me and my vast and unfathomable intellect

  • 0

I’ve got this question that’s been bugging me and my vast and unfathomable intellect just can’t grasp it. The case: I want to make multiple one-to-many relationships to the same entity using the fluent nhibernate automapper and export schema.

I have:

Base Class:

 public abstract class Post<T> : Entity, IVotable, IHierarchy<T>
 {
    public virtual string Name
    {
        get; set;
    }

    public virtual string BodyText
    {
        get; set;
    }

    public virtual Member Author
    {
        get; set;
    }
}

and Inheriting Class:

 [Serializable]
public class WallPost : Post<WallPost>
{
    public virtual Member Receiver
    {
        get; set;
    }
}

The ‘Member’ properties of WallPost is a foreign key relationship to this class:

public class Member : Entity
    {
        public Member()
        {
           WallPosts = new IList<WallPost>();
        }

 public virtual IList<WallPost> WallPosts
        {
            get; set;
        }
}

I hope you’re with me until now. When I run the exportschema of nhibernate I expect to get a table wallpost with ‘author_id’ and ‘receiver_id’ BUT I get author_id, receiver_id,member_id. Why did the Nhibernate framework add member_id, if it’s for the collection of posts (IList) then how do you specify that the foregin key relationship it should use to populate is receiver, i.e. member.WallPosts will return all the wallposts of the receiver.

I hope i made sense, if you need anything else to answer the question let me know and I’ll try to provide.

Thanks in advance

P.s. If I change the property name from ‘Receiver’ to ‘Member’ i.e. public virtual Member Member, only two associations are made instead of 3, author_id and member_id.

E

THE SOLUTION TO THIS QUESTION FOR ANYONE ELSE WONDERING IS TO ADD AN OVERRIDE:

mapping.HasMany(x => x.WallPosts).KeyColumn("Receiver_id");
  • 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-21T16:31:14+00:00Added an answer on May 21, 2026 at 4:31 pm

    Most likely (I don’t use auto mapping, I perfer to write my own classmaps) it’s because the auto mapping assuming that your Member’s “WallPosts” is controled by the wall posts. So it creates a member_id for that relationship.

    Edit: Try adding an override in your fluent config, after AutoMap add:

    .Override<Member>(map =>
    {
      map.HasMany(x => x.WallPosts, "receiver_id")
        .Inverse;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.