【发布时间】:2021-10-04 20:56:56
【问题描述】:
我在模型课上学习关系。有关表格关系,请参阅附图。 共有三个表,部门、员工、位置。 当为这些表创建模型类时,我对导航属性感到困惑。 员工等级:
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}
}
为什么在employee 类中department 被定义为virutal department department 而location 被定义为virtual ICollection<location> locations。为什么只对定位使用ICollection?
在department 模型中,employee 类定义为virutal ICollection<employee> employees,但在location 模型中,员工定义为virutal employee employee。为什么会这样,请澄清。
同样在employee类中location被定义为HashSet<location>()在constructor中,为什么会这样定义呢?这个导航属性让我在项目中继续前进感到困惑。请让我澄清一下。谢谢!!!
【问题讨论】:
标签: asp.net asp.net-mvc entity-framework asp.net-mvc-4 navigational-properties