たとえば、次の 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) これは 1 つまたは 2 つの協会ですか?
2) と の間に 2 番目の関連付けを作成できますDepartment.Manager
かEmployee.Id
? マネージャーを別のテーブルに保存したくないので、従業員テーブルにも保存され、Position
フィールド「マネージャー」にあります。