我是 Entity Framework 和 C#/.Net 的新手,正在尝试创建 TPH 继承模型,我不确定我是否应该这样做,所以如果不是,请告知,
这是模型:
public abstract class Vote
{
public int VoteID { get; set; }
public int UserID { get; set; }
public bool Value { get; set; }
public DateTime DateCreated { get; set; }
public User User { get; set; }
}
public class ProjectVote_ : Vote
{
public int ProjectID { get; set; }
public virtual Project Project { get; set; }
}
public class CommentVote_ : Vote //There are three more like this, votes for different hings
{
public int CommentID { get; set; }
public virtual Comment Comment { get; set; }
}
现在的项目模型(评论和模型相似)
public class Project
{
public int ProjectID { get; set; }
public string Title { get; set; }
public virtual ICollection<Vote> Vote { get; set; }
}
发生的情况是 ICollection 创建了一个数据库列 Project_ProjectID 作为 Vote 表中的外键(我认为),而不是使用我定义的 ProjectID。我该如何修复它,或者我应该以不同的方式对其进行建模。如果 fluent API 是修复它的方法,我不知道该怎么做。
最后,我希望能够使用一张表来存储 5 种不同类型的选票。