by using Table per Type (TPT) inheritance in Entity Framework codefirst we can create foreign keys like this :
public abstract class Person
{
public int id { get; set; }
public string Name { get; set; }
public string Family { get; set; }
}
[Table("Doctors")]
public class Doctor : Person
{
public string ExpertTitle { get; set; }
}
[Table("Notes")]
public class Note : Doctor
{
public string Content { get; set; }
}
in above code In addition to the creating Doctors table and relating that with Persons table, we could create Note table and create 1-to-Many relation between Doctors Table and that.
but is that standard to create all foreign keys using inheritance instead of using virtual properties like what you see bellow?!
public class Doctor : Per
{
public string ExpertTitle { get; set; }
public virtual ICollection<Note> Notes { get; set; }
}
public class Note : Doctor
{
public string Content { get; set; }
public virtual Doctor Doctor { get; set; }
}
NotefromDoctor? I would model your classes logically and independently from the ORM. You wouldn't use inheritance just for creating a relationship. - user2697817