I have two entities Employee, Branch
public class Branch
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; }
public int ManagerId { get; set; }
public Employee Manager { get; set; }
public List<Employee> Employees { get; set; }
public List<Department> Departments { get; set; }
}
public class Employee
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public int ManagerId { get; set; }
public Employee Manager { get; set; }
public int DepartmentId { get; set; }
public Department Department { get; set; }
public int BranchId { get; set; }
public Branch Branch { get; set; }
}
each branch has many departments, each department has many employees, each employee belong to one department and one branch
the database scheme should look like this :
Branch : Id , Name , ManagerId
Department : Id , Name , ManagerId
Employee : Id , Name , DepartmentId , BranchId, ManagerId #(department manager)
I want to have OneToOne relationship for Branch with Employee (Manager), and OneToMany relationship for Branch with Employee (Employees Of Branch)
right now when I try to add migrations, it fails with
Unable to determine the relationship represented by navigation property 'Branch.Manager' of type 'Employee'
I understand the issue, but not able to solve it.