我有两个表,Participant
并且Meeting
在 ASP.NET Core 6 最小 API 项目中设置如下:
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>();
}
现在我需要创建一个连接这两个表/记录的组合表/记录
在 SQL 中,这将是这张表
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)
);
但是我如何将它作为带有外键的记录写在 EF 中?