如何解决复合键与外键 EF Core 的关系
我有两个类,我想在它之间建立关系。流动的类:
public class LecturGroup
{
public int GroupId { get; set; }
public Group Group { get; set; }
public int TeacherId { get; set; }
public Teacher Teacher { get; set; }
public int LectureId { get; set; }
public Lecture Lecture { get; set; }
public IList<Choice> Choices { get; set; }
}
public class Choice
{
public int StudentId { get; set; }
public Student Student { get; set; }
public int LecturGroupId { get; set; }
public LecturGroup LecturGroup { get; set; }
}
为了将 LecturGroup
中的 3 个复合键引用到 LecturGroupId
类中的 Choice
,我使用了 Fluent API,如下所示:
modelBuilder.Entity<Choice>().HasKey(s => new { s.StudentId,s.LecturGroupId });
modelBuilder.Entity<LecturGroup>().HasKey(s => new { s.GroupId,s.TeacherId,s.LectureId });
我只想在 3 个复合键 (GroupId
,TeacherId
,LectureId
) 之间建立关系,即同时存在外键和另一个复合键中的一个 ({{ 1}}).
如何处理?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。