許多和自我引用我有以下關係的兩個實體(這些實體採取唯一的例子的目的)一個在實體框架
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