I am reading through this tutorial.... ASP.NET Code First MVC Tutorial
In this example, Student Class has the "ID" property.
Enrollment Class has "StudentID" property.
Now, If all the additional definition in Enrollment class says,
public virtual Student Student { get; set; }
Just by that statement, will the EF know that StudentID is foreign key?
My confusion is, in the Student Table, property name is "ID" .. Say in the Enrollment Class, instead of StudentID, I call it.... Student_ID....will the EF still correlate Student.ID as the same as Enrollment.Student_ID and establish foreign key? Does it just need the "Student" string in a property name in Enrollment class to establish relationship?
Code snippets from the site...
using System;
using System.Collections.Generic;
namespace ContosoUniversity.Models
{
public class Student
{
public int ID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
}
}
namespace ContosoUniversity.Models
{
public enum Grade
{
A, B, C, D, F
}
public class Enrollment
{
public int EnrollmentID { get; set; }
public int CourseID { get; set; }
public int StudentID { get; set; }
public Grade? Grade { get; set; }
public virtual Course Course { get; set; }
public virtual Student Student { get; set; }
}
}