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";