实体框架核心自我引用图
我在Blazor Server项目中使用EF Core。我有一个称为课程的实体。 A 课程可以拥有一个或多个先决条件课程,必须在访问它之前完成。
我希望在可能的情况下使用数据注释来完成建立此关系。
(已编辑的)方法是否正确?
public class Lesson : EntityBase
{
public List<LessonPrerequisiteLesson> PrerequisiteLessons { get; set; }
}
public class LessonPrerequisiteLesson : EntityBase
{
public int LessonID { get; set; }
public int PrerequisiteLessonID { get; set; }
[ForeignKey("PrerequisiteLessonID")]
[InverseProperty("PrerequisiteLessons")]
public Lesson PrerequisiteLesson { get; set; }
}
I am using EF Core in my Blazor Server project. I have an entity called Lesson. A Lesson can have one or more prerequisite Lessons that must be completed before it is accessible.
I would prefer to use data annotations to accomplish setting up this relationship if possible.
Is the (redacted) approach below correct?
public class Lesson : EntityBase
{
public List<LessonPrerequisiteLesson> PrerequisiteLessons { get; set; }
}
public class LessonPrerequisiteLesson : EntityBase
{
public int LessonID { get; set; }
public int PrerequisiteLessonID { get; set; }
[ForeignKey("PrerequisiteLessonID")]
[InverseProperty("PrerequisiteLessons")]
public Lesson PrerequisiteLesson { get; set; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论