我在模型课上学习关系。有关表格关系,请参阅附图。有三个表,部门,员工,位置。当为这些表创建模型类时,我对导航属性感到困惑。员工等级:
public class employee
{
public employee()
{
this.location = new HashSet<location>();
}
//attributes
public virutal department department {get;set}
public virtual ICollection<location> locations {get;set}
}
然后在部门班:
public class department
{
//attributes
public virutal ICollection<employee> employees {get;set}
}
在位置类中:
public class location
{
public virutal employee employee {get;set}
}
为什么 in employee
classdepartment
被定义为 likevirutal department department
但location
被定义为virtual ICollection<location> locations
. 为什么ICollection
只使用位置?
在department
模型中,employee
类被定义为,virutal ICollection<employee> employees
但在location
模型中雇员被定义为virutal employee employee
。为什么会这样,请澄清。
同样 in employee
classlocation
定义为HashSet<location>()
in constructor
,为什么要这样定义?这个导航属性让我在项目中继续前进感到困惑。请让我澄清一下。谢谢你!!!