I have two tables, Participant
and Meeting
, in an ASP.NET Core 6 minimal API project set up like this:
record Participant(int id)
{
public string name { get; set; } = default!;
public string title { get; set; } = default!;
}
record Meeting(int id)
{
public string subject { get; set; } = default!;
public string organizer { get; set; } = default!;
public DateTime starttime { get; set; } = default!;
public DateTime endtime { get; set; } = default!;
}
class MyDb: DbContext
{
public MyDb(DbContextOptions<MyDb> options): base(options)
{
}
public DbSet<Participant> Participants => Set<Participant>();
public DbSet<Meeting> Meetings => Set<Meeting>();
}
Now I need to create a combining table / record which connects these two tables / records
In SQL this would be this table
CREATE TABLE meetings_participants
(
meeting_id int NOT NULL,
participant_id int NOT NULL,
PRIMARY KEY (meeting_id, participant_id),
CONSTRAINT fk_meeting_id
FOREIGN KEY (meeting_id) REFERENCES meetings(id),
CONSTRAINT fk_participant_id
FOREIGN KEY (participant_id) REFERENCES participants(id)
);
But how do I write it in EF as a record with foreign keys ?