Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对于我的情况,EF中最适合的继承类型是什么?_C#_Entity Framework_Ef Code First - Fatal编程技术网

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,但我想让代码变得如此简单,我不喜欢使用导航属性。