每种类型的表(TPT)层次结构与实体框架中的导航

时间:2018-01-29 11:26:51

标签: c# .net sql-server entity-framework

我在几周内一直在阅读有关实体框架的内容。我遇到了TPT主题。我有点困惑,难以区分TPT和导航。什么时候应该选择另一个。请看下面的代码。

:一种。 Navication

 public class Employee
{
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Gender { get; set; }

    public List<ContractEmployee> ContractEmployees { get; set; }
    public List<PermanentEmployee> PermanentEmployees { get; set; }

}

public class ContractEmployee 
{
    public int HourlyWorked { get; set; }
    public int HourlyPay { get; set; }
    public Employee Employee { get; set; }

}

public class PermanentEmployee 
{
    public int AnnualSalary { get; set; }
    public Employee Employee { get; set; }
}

B中。 TPT

[Table("Employee")]
public class Employee
{
    public int EmployeeId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Gender { get; set; }

}

[Table("ContractEmployee")]
public class ContractEmployee : Employee
{
    public int HourlyWorked { get; set; }
    public int HourlyPay { get; set; }

}

[Table("ContractEmployee")]
public class PermanentEmployee : Employee
{
    public int AnnualSalary { get; set; }
}

0 个答案:

没有答案