Entity Framework 模型上相同 table 的两个外键元素?

Two foreign key elements of the same table on an Entity Framework model?

我正在尝试使用 Entity Framework 创建一个数据库 table,它将有两列,一列用于 Person,另一列用于 。换句话说,将有两个外键,每个外键将指向同一个 table.

上的两个不同记录

Whosebug 和其他地方的 one question that most nearly matches my situation isn't written well and has no answers. 处理许多多条记录的集合。在我的情况下,我 只是 需要知道如何在一个模型上为同一个 table 设置两个外键。

我觉得这不对,Visual Studio 也不喜欢,因为代码引用了 Person 两次。

public class Lesson
{
    [Key]
    public int LessonId { get; set; }

    [ForeignKey("Person")]
    [Column(Order = 0)]
    public string studentId { get; set; } 
    public Person Person { get; set; }

    [ForeignKey("Person")]
    [Column(Order = 1)]
    public string teacherId { get; set; }
    public Person Person { get; set; }
}

这对你来说合适吗?我试图解决错误的问题吗? ...或者,更好的是,是否有一些语法可以使它起作用?

Does this look right to you?

没有。 尝试类似的东西:

public class Lesson
{
    [Key]
    public int LessonId { get; set; }

    [ForeignKey("Student")]
    public string StudentId { get; set; } 
    public Person Student { get; set; }

    [ForeignKey("Teacher")]
    public string TeacherId { get; set; }
    public Person Teacher{ get; set; }

}