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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:45:47+00:00 2026-06-03T03:45:47+00:00

I have two tables with a many-to-many relation with a bridge table. User Class

  • 0

I have two tables with a many-to-many relation with a bridge table.

User Class Mapping :

<class name="MatrixCore.User" table="MatrixUser" lazy="false">
    <id name="ID" column="ID" unsaved-value="0">
      <generator class="native"/>
    </id>
    <property name="FirstName"/>
    <property name="LastName"/>
    <property name="UserName"/>
    <property name="Password"/>
    <many-to-one name="UserType" class="MatrixCore.UserType" />
    <set name="Projects" table="UserInProject" cascade="All">
      <key column="MatrixUser_ID"/>
      <many-to-many class="Project" column="Project_ID"/>
    </set>
  </class>

Project class mapping :

<class name="MatrixCore.Project" table="Project" lazy="false">
   <id name="ID" column="ID" unsaved-value="0">
     <generator class="native"/>
   </id>
   <property name="Name" />
   <property name="Acronym"/>
   <property name="StartDate"/>
   <property name="EndDate"/>
   <set name="Users" table="UserInProject" cascade="All">
     <key column="Project_ID"/>
     <many-to-many class="User" column="MatrixUser_ID" />
   </set>
</class>

the classes implementations are too simple each class have a collection
of the other.
I am trying to insert records in the tables the bridge table keep to be empty.

    ICollection<Project> ps = new HashSet<Project>() { project};

            UserType tp = (UserType)session.Get("UserType", 1);
            User u = new User()
            {
                FirstName = "Hussein",
                LastName = "Hussein",
                UserName = "Hussein",
                Password = "welcome",
                UserType = tp,
                Projects = ps
            };

            session.Save(u);
  • 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-06-03T03:45:49+00:00Added an answer on June 3, 2026 at 3:45 am

    try this mapping
    for user class

    <set name="Projects" table="UserInProject" inverse="true" cascade="save-update" lazy="false">
      <key column="MatrixUser_ID" />
      <many-to-many class="Project" column="Project_ID"/>
    </set>
    

    and for Project Class

    <set name="Users" table="UserInProject" cascade="save-update" lazy="false">
      <key column="Project_ID"  />
      <many-to-many class="User" column="MatrixUser_ID"/>
    </set>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes with many-to-many relation so I created a join table in-between
I have two tables with a many to many relationship, through a third table.
I have two tables, products and product_tags . products table; product_id int name varchar
I have a many-to-many relation in 3 tables: ProgramUserGroup and Feature are the two
I have two tables: Items and Colors. They have a many to many relation.
My DB have two tables - Question and Topic. To implement many-to-many relation, there
Lets say I have two tables - child and parent with many-to-one relation. What
I have two tables and I need to establish a 1-many relation among them,
Let's say we have two tables with a many-to-many relationship: public class Left{ /**/
I have two tables Companies and Contact with relation one to many, and I

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.