I was learning relationships in model classes. Please see the attached image for the table relationships. There are three tables, department, employee, location. When model classes are created for these tables, I am confused regarding navigational property. employee class:
public class employee
{
public employee()
{
this.location = new HashSet<location>();
}
//attributes
public virutal department department {get;set}
public virtual ICollection<location> locations {get;set}
}
then in department class:
public class department
{
//attributes
public virutal ICollection<employee> employees {get;set}
}
in location class:
public class location
{
public virutal employee employee {get;set}
}
Why in employee class department is defined like virutal department department but location is defined as virtual ICollection<location> locations. Why using ICollection only with locataion?
And in department model, employee class is defined as virutal ICollection<employee> employees but in location model employee is defined as virutal employee employee. Why is it so, please clarify.
Also in employee class location is defined as HashSet<location>() in constructor, and why is it defined like this ? This navigational property is making me confused to proceed further in the project. Please make me clarify regarding this. Thank You!!!
