public class Person
{
[Key]
public int ID { get; private set; }
[Required]
[StringLength(100)]
public string PersonName { get; set; }
}
Creates People table:
ID | PersonName | School_ID | School_ID1
public class School
{
[Key]
public int ID { get; private set; }
[Required]
[StringLength(100)]
public string SchoolName { get; set; }
public virtual List<Person> Students { get; set; }
public virtual List<Person> Teachers { get; set; }
}
Creates Schools table:
ID | SchoolName
Using the above simple model, Entity Framework (using v6.0) creates two FKs on People table as expected. The mapping is fine - it works, but it doesn't look nice on the database and would prefer to have the FKs called
School_Teacher_ID, School_Student_ID
Any help, very much appreciated.
ADDITIONAL NOTE:
I know I can use the ForeignKey DataAnnotation (on School), but this requires me to add the FK (on Person) which is leaking storage concerns into the model and adds overhead that simply isn't necessary.
To expand slightly on the overhead:
In the example I was creating to understand this I also created other classes that contained List<Person> (e.g. Club->Members, Company->Employees) and to employ the FK DA I would need to add an additional property for each of the classes using List<Person> on Person.
e.g. Company_Employee_ID, Club_Member_ID, School_Student_ID, School_Teacher_ID
LINK to code: https://www.dropbox.com/s/ataer5zndo0c6bc/Program.cs?dl=0
CONCLUSION SO FAR: Until I get a better understanding of Fluent API my best option looks to be editing the create code produced by enabling Migrations.