实体是Programmer
和Engineer
。我想探索实体框架中的IS-A选项。请问有人可以告诉我如何使用实体框架(代码优先或数据库第一)实现“是”关系吗?
我有这样的课程:
Employee
答案 0 :(得分:0)
Is-A关系是继承,而在EF中实现这种关系的一种可能方法如下:
public class Employee
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Programmer
{
[ForeignKey(nameof(Employee))]
public int Id { get ; set ; }
public virtual Employee {get;set;}
double HRate { get; set; }
}
public class Engineer: Employee
{
[ForeignKey(nameof(Employee))]
public int Id { get ; set ; }
public virtual Employee {get;set;}
double MRate { get; set; }
}