Why Employee table of NORTHWND database has a self reference?

273 views Asked by At

I generated an object model of the Employee table of the NORTHWND database, using the object relational designer.

Why does the Employee class has a self reference?:

enter image description here

This is the relevant part of the generated 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;
}
1

There are 1 answers

0
sorjef On BEST ANSWER

I assume you refer to this NORTHWIND database.

The Employee entity has a self-reference because it contains a foreign key ReportsTo, which is probably meant to reflect a hierarchy of employees in imaginary Northwind company.

This foreign key also shows that the relationship is defined as 1 to * (many). Hence, there can be only 1 supervisor to whom the employee reports to, but a supervisor can have many employees reporting to him or her.