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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:23:37+00:00 2026-05-10T15:23:37+00:00

I am using Fluent NHibernate and having some issues getting a many to many

  • 0

I am using Fluent NHibernate and having some issues getting a many to many relationship setup with one of my classes. It’s probably a stupid mistake but I’ve been stuck for a little bit trying to get it working. Anyways, I have a couple classes that have Many-Many relationships.

public class Person {     public Person()     {         GroupsOwned = new List<Groups>();     }      public virtual IList<Groups> GroupsOwned { get; set; } }  public class Groups {     public Groups()     {         Admins= new List<Person>();     }      public virtual IList<Person> Admins{ get; set; } } 

With the mapping looking like this

Person: …

HasManyToMany<Groups>(x => x.GroupsOwned)     .WithTableName('GroupAdministrators')     .WithParentKeyColumn('PersonID')     .WithChildKeyColumn('GroupID')     .Cascade.SaveUpdate(); 

Groups: …

 HasManyToMany<Person>(x => x.Admins)     .WithTableName('GroupAdministrators')     .WithParentKeyColumn('GroupID')     .WithChildKeyColumn('PersonID')     .Cascade.SaveUpdate(); 

When I run my integration test, basically I’m creating a new person and group. Adding the Group to the Person.GroupsOwned. If I get the Person Object back from the repository, the GroupsOwned is equal to the initial group, however, when I get the group back if I check count on Group.Admins, the count is 0. The Join table has the GroupID and the PersonID saved in it.

Thanks for any advice you may have.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T15:23:38+00:00Added an answer on May 10, 2026 at 3:23 pm

    The fact that it is adding two records to the table looks like you are missing an inverse attribute. Since both the person and the group are being changed, NHibernate is persisting the relation twice (once for each object). The inverse attribute is specifically for avoiding this.

    I’m not sure about how to add it in mapping in code, but the link shows how to do it in XML.

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

Sidebar

Related Questions

I'm having a problem with a pretty simple setup in NHibernate. (I'm using Fluent
I'm having some trouble getting NHV to work with Fluent NHibernate. A unit test
I'm using ASP.NET MVC + NHibernate + Fluent NHibernate and having a problem with
If using Fluent NHibernate, is it possible to automap most classes, but specify that
I'm using Fluent NHibernate auto mapping. I need to access more than one database
I'm using Fluent NHibernate, and auto-mapping the classes. I have a computed property in
I'm having problems deleting a row using fluent nhibernate. If i execute the below
I am using Fluent NHibernate and NHibernate.Core 3 beta 1. I have two classes:
I am using fluent nhibernate(v1.2) and nhibernate(v3.1) and I am having a weird Problem.
Having problems with my ASP.NET MVC2 project. I'm using Fluent NHibernate as ORM, and

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.