嗨,我刚开始学习使用实体框架代码,我似乎无法理解某些东西。我根据教程创建了三个模型:
public class Course
{
public int CourseID { get; set; }
public string Title { get; set; }
public int Credits { get; set; }
public virtual ICollection<Enrollment> Enrollments{ get; set; }
}
public class Enrollment
{
public int EnrollmentID { get; set; }
public int CourseID { get; set; }
public int StudentID { get; set; }
public decimal? Grade { get; set; }
public virtual Course Course { get; set; }
public virtual Student Student { get; set; }
}
public class Student
{
public int StudentID { get; set; }
public string LastName { get; set; }
public string FirstMidName { get; set; }
public DateTime EnrollmentDate { get; set; }
public virtual ICollection<Enrollment> Enrollments { get; set; }
}
我的问题是我不明白虚拟属性的作用。如果我检查数据库,每个属性都没有列箱,只有其他属性。
那么当您使用 virtual 关键字创建属性时会发生什么?