我正在尝试使用继承在 EF6 中实现模型
我有以下课程:
基本
评论
页面:基本
博客帖子:基本
Page 和 BlogPost 都以相同的方式使用评论。所以我将 Base 定义为
public class Base
{
public int ID { get; set; }
// ...
public ICollection<Comment> Comments { get; set; }
}
并且评论类定义如下:
public class Comment
{
public int ID { get; set; }
public int RelatedItemID { get; set; } // points to Base::ID
public string Text { get; set; }
}
假设我想将数据库设置为“每种类型的表”,因此 Page 和 BlogPost 都有单独的表,每个表都具有自动增量 int PK。
现在 EF 知道 Comment.RelatedItemID 指向哪个表了吗?即页面或博客帖子
无需求助于“每个层次结构的表”来实现这一点的最佳方法是什么?