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 some trouble getting NHV to work with Fluent NHibernate. A unit test
I'm using Fluent NHibernate and the setup I have is as follows: An Address
If using Fluent NHibernate, is it possible to automap most classes, but specify that
Having problems with my ASP.NET MVC2 project. I'm using Fluent NHibernate as ORM, and
Is it possible to map an enum as a string using Fluent Nhibernate?
I'm using NHibernate and Fluent NHibernate to create a mapping file for a domain
I've just started using NHibernate and fluent-NHibernate which I think is great. I've been
Hi Im curious about how DDD is really implemented using Fluent Nhibernate. for example
Just started developing a project using NHibernate and Fluent NHibernate for the mapping and
using fluent nhibernate, and automappings (nhibernate creates my db schema), how can i get

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.