【发布时间】:2017-09-22 15:05:37
【问题描述】:
场景:
public class Department
{
public int DepartmentId { get; set; }
public string DepartmentName { get; set; }
public string Description { get; set; }
public DateTime CreatedOn {get; set; }
public string CreatedBy {get; set; }
}
public class TestItem
{
public int TestItemId { get; set; }
public string TestItemName { get; set; }
public Department Department { get; set; }
public int DepartmentId { get; set; }
public DateTime CreatedOn {get; set; }
public string CreatedBy {get; set; }
}
public class Patient
{
public int PatientId { get; set; }
public string PatientName { get; set; }
public DateTime CreatedOn {get; set; }
public string CreatedBy {get; set; }
}
问题是,每次创建表时,我都必须重复添加这两列。
但我想要这样-
public class EntryLog
{
public int EntryLogId { get; set; }
public DateTime CreatedOn {get; set; }
public string CreatedBy {get; set; }
}
public class Department
{
public int DepartmentId { get; set; }
public string DepartmentName { get; set; }
public string Description { get; set; }
public EntryLog EntryLog { get; set; }
public int EntryLogId { get; set; }
}
and so on...
class A { .. }
class B { .. }
但是在为部门或患者创建行时会出现问题 [显示与其他表的外键冲突错误]。
在 EF 核心中,有 Table Per Hierarchy (TPH),但在这种情况下,每个表都将合并为一个表。但这并没有给我任何解决方案。
期待专家的建议……
【问题讨论】:
标签: entity-framework inheritance asp.net-core-mvc