Modify Student

Modify the student class

Modify the student class as shown below

namespace EFGetStarted
{
    public class Student
    {
        public Student() => Vehicles = new HashSet<Vehicle>();
        public int Id { get; set; }
        public string Name { get; set; }
        public bool IsEnrolled { get; set; }
        public string City { get; set; }
        public ICollection<Vehicle> Vehicles { get; set; }
    }
}

note the following here

  • the vehicles property is called a (collection) navigation property

    • it is required as per the relationship in our domain which says one student can have many vehicles associated with him (one to many)

  • hash set is very similar to List datatype, but prevents duplicate entries, so it gives an additional safety. We could have used list collection as well

  • the constructor is initializing the Vehicles collection to avoid checking for null collection later in the code. It is not mandatory but more of a convenience

Last updated