简体   繁体   English

我的案例中EF中最适合的继承类型是什么?

[英]What is the fittest inheritance type in EF for my case?

i have the flowing classes: 我有流动的班级:

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

and i want the database tables to be looks like: - People table:(id,...,createdat, updatedat); 我希望数据库表看起来像:-人员表:(id,...,createdat,updatedat); - Employee table:(id, ..., createdat, updatedat); -员工表:(id,...,createdat,updatedat);

and in the code, when i need the person creation date i will do: Employee em ; 在代码中,当我需要人员创建日期时,我将执行以下操作:Employee em; datetime pcd = (Person)em.CreatedAt; datetime pcd =(Person)em.CreatedAt; and when i need employee creation date: datetime ecd = em.CreatedAt; 当我需要员工创建日期时:datetime ecd = em.CreatedAt;

please what is the fittest inheritance type for my case? 请问我的情况最适合的继承类型是什么?

I think the way you're going is too complicated. 我认为您的前进方式过于复杂。 If I understand you right - you need to separate PersonCreateDate and EmployeeCreateDate . 如果我理解正确,则需要将PersonCreateDateEmployeeCreateDate分开。

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

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

In database, Employee must have a foreign key to Person . 在数据库中, Employee必须具有Person的外键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM