为什么 NORTHWND 数据库的 Employee table 有一个自引用?

Why Employee table of NORTHWND database has a self reference?

我使用对象关系设计器生成了 NORTHWND 数据库的 Employee table 的对象模型。

为什么员工 class 有自我引用?:

这是生成的相关部分class:

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Employees")]
    public partial class Employee : INotifyPropertyChanging, INotifyPropertyChanged
{
        // ... other properties ...

        private EntitySet<Employee> _Employees;

        private EntityRef<Employee> _Employee1;
}

我假设你指的是 this NORTHWIND database

Employee 实体有一个自引用,因为它包含一个外键 ReportsTo,这可能是为了反映虚构的 Northwind 公司中的员工层次结构。

这个外键也说明关系定义为1到*(多)。因此,员工只能有 1 个主管,但一个主管可以有多个员工向他或她报告。