许多和自我引用我有以下关系的两个实体(这些实体采取唯一的例子的目的)一个在实体框架
public class Entity
{
public long ID { get; set; }
}
public class Doctor : Entity
{
public string Name {get; set;}
public string sprcialization { get; set;}
public string Icollection<JrDoctor> childDoctors { get; set;}
}
public class JrDoctor : Entity
{
public long? DoctorId { get; set;}
public virtual Doctor Doctor { get; set;}
public long? JuniorDoctorId { get; set;}
[ForeignKey("JuniorDoctorId")]
public virtual Doctor JuniorDoctor { get; set;}
}
中的EntityFramework这种关系是建立在JrDoctor表一个额外的列Doctor_Id。为什么这样?以及如何使用数据注释来避免它。
“Doctor”实体中的关键是什么?关于'JrDoctor'实体的同样问题? –
@SergeyBerezovskiy ID是这两个表中的关键字,更新了问题 – DivideByzero