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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:14:12+00:00 2026-06-15T12:14:12+00:00

I have two tables and I wand to create a junction table. I have

  • 0

I have two tables and I wand to create a junction table. I have this mapping.

public UsertMap()
    {
        Table("Users");
        Id(x => x.Id, map => map.Generator(Generators.Assigned));
        Property(x => x.FirstName, map => map.NotNullable(true));
        Property(x => x.LastName, map => map.NotNullable(true));
        Property(x => x.Role, map => map.NotNullable(true));
        Bag(x => x.Projects, map =>
        {
            map.Table("UsersInProject");
            map.Cascade(Cascade.None);
            map.Access(Accessor.Field);
            map.Key(u => u.Column("UserId")); 
            }, a => a.ManyToMany(x => x.Column("ProjectId")));
    }

and

public ProjectMap()
    {
        Table("Projects");
        Id(x => x.Id, map => map.Generator(Generators.Assigned));
        Property(x => x.SubmissionDate, map =>map.NotNullable(true));
        Property(x => x.QuotesubmissionDate, map => map.NotNullable(true));
        Bag(x => x.ProjectUsers, map =>
        {
            map.Table("UsersInProject");
            map.Cascade(Cascade.None);
            map.Access(Accessor.Field);
            map.Key(u => u.Column("ProjectId"));
        }, a => a.ManyToMany(x => x.Column("UserId")));
    }

It created the junction table but without setting as primary key*, the composite key {ProjectId , UserId}

What am I doing wrong?

Thanx in advance.

*It was strange for me to understand it also when i was told of this about me code.
The created table is created by this sql code:

CREATE TABLE "UsersInProject"
(
  "ProjectId" uuid NOT NULL,
  "UserId" uuid NOT NULL,
  CONSTRAINT fk28998796db607aa2 FOREIGN KEY ("UserId")
      REFERENCES "Users" ("Id") MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT fk28998796f9a8d344 FOREIGN KEY ("ProjectId")
      REFERENCES "Projects" ("Id") MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITH (
  OIDS=FALSE
);
ALTER TABLE "UsersInProject"
  OWNER TO test;

I would expece also a line like the next in there:

CONSTRAINT pk PRIMARY KEY ("ProjectId" , "UserId" ),

edit2: (for a better view)

drop table if exists "UsersInProject" cascade;
create table "UsersInProject" (
        "ProjectId" uuid not null,
       "UserId" uuid not null
    );
    alter table "UsersInProject" 
        add constraint FK28998796DB607AA2 
        foreign key ("UserId") 
        references "Users";

    alter table "UsersInProject" 
        add constraint FK28998796F9A8D344 
        foreign key ("ProjectId") 
        references "Projects";
  • 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-15T12:14:13+00:00Added an answer on June 15, 2026 at 12:14 pm

    I came to the conclusion that in order to have a composite primary key in nHibernate you’ll have to use another column to be used for the update of the row in the database by the nHibernate.

    More of this here:
    http://devlicio.us/blogs/anne_epstein/archive/2009/11/20/nhibernate-and-composite-keys.aspx

    I believe that because of that, you must add more columns (1 column to be precice) in the junction table to achieve what i wanted.

    Enjoy!

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

Sidebar

Related Questions

I have two tables, A and B. The structure looks like this: CREATE TABLE
I have two tables in a page like this: <table style=width:800px> <tr> <td style=width:400px;>
I have two tables users registered_members I want to confirm values from user table
Have two tables: CREATE TABLE IF NOT EXISTS `issue_details` ( `id` INT NOT NULL
I have two tables with the following definitions: CREATE TABLE [dbo].[Shows] ( [Id] UNIQUEIDENTIFIER
I have two tables: CREATE TABLE tblEatables ( `EatId` int UNSIGNED PRIMARY AUTO_INCREMENT, `Fruits`
Have two tables with a linking table between them. USERS +-------+---------+ | userID| Username|
I have two tables USERS and CALENDER, in calender table user place his availability
I have two tables Like Below CREATE TABLE projectlist(ProjectId INT NOT NULL PRIMARY KEY,
I have two tables: table a ida valuea 1 a 2 b 3 c

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.