2014-12-20 34 views
0

我有流动类:对于我的情况,EF中最适合的继承类型是什么?

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;} 
    // ... 
} 

,我想数据库表是看起来像: - People表:(ID,...,createdat,updatedat); - 员工表:(id,...,createdat,updatedat);

并且在代码中,当我需要人员创建日期时,我会这样做: Employee em; datetime pcd =(Person)em.CreatedAt; 当我需要员工创建日期: datetime ecd = em.CreatedAt;

请问我的案例最适合的继承类型是什么?

回答

0

我觉得你要走的路太复杂。如果我理解你的话 - 你需要分开PersonCreateDateEmployeeCreateDate

public class Person 
{ 
    public DateTime CreateDate {get;set;} 
} 

public class Employee 
{ 
    public DateTime CreateDate {get;set;} 
    public virtual Person BasedOnPerson {get;set;} 
} 

在数据库中,Employee必须有一个外键Person

+0

谢谢@JesseJames,但我想让代码如此简单,我不喜欢使用导航属性。 –

相关问题