例如,我有 2 个实体:
public class Department
{
public Guid Id { get; set; }
public string Name { get; set; }
public ICollection<Employee> Employees { get; set; }
public Employee Manager { get; set; }
}
public class Employee
{
public Guid Id { get; set; }
public string FullName { get; set; }
[ForeignKey("DepartmentId")]
public Department Department { get; set; }
public Guid DepartmentId { get; set; }
public string Position { get; set; }
}
我知道我可以(正如我已经做过的那样:)Department.Employees
与Employee.Id
(反之:Employee.Department
与Department.Id
)相关联。
问题:
1)这是一两个协会吗?
2) 我可以在Department.Manager
和之间创建第二个关联Employee.Id
吗?不想将经理存储在另一个表中,因此它们也存储在 Employee 表中并在Position
字段“Manager”中。