C# 对于我的情况,EF中最适合的继承类型是什么?
我有流动的课程:C# 对于我的情况,EF中最适合的继承类型是什么?,c#,entity-framework,ef-code-first,C#,Entity Framework,Ef Code First,我有流动的课程: public abstract class Person { //... public DateTime CteatedAt{get;set;} public DateTime UpdatedAt{get;set;} // .... } public class Employee : Person { // ... public DateTime CreatedAt{get;set;} public DateTime U
public abstract class Person
{
//...
public DateTime CteatedAt{get;set;}
public DateTime UpdatedAt{get;set;}
// ....
}
public class Employee : Person
{
// ...
public DateTime CreatedAt{get;set;}
public DateTime UpdatedAt{get;set;}
// ...
}
我希望数据库表如下所示:
-人员表:(id,…,createdat,updatedat);
-员工表:(id,…,createdat,updatedat)
在代码中,当我需要人员创建日期时,我将执行以下操作:
雇员薪酬;
datetime pcd=(Person)em.CreatedAt;
当我需要员工创建日期时:
datetime ecd=em.CreatedAt
请问什么样的继承类型最适合我的情况?我认为你的方式太复杂了。如果我没弄错的话-你需要将
PersonCreateDate
和EmployeeCreateDate
分开
public class Person
{
public DateTime CreateDate {get;set;}
}
public class Employee
{
public DateTime CreateDate {get;set;}
public virtual Person BasedOnPerson {get;set;}
}
在数据库中,
Employee
必须有一个指向Person
的外键,谢谢@JesseJames,但我想让代码变得如此简单,我不喜欢使用导航属性。