Good afternoon, I would like to ask a relationship question in Entity Core. I have a person table and the person has a position (Manager, supervisor, responsible, etc ...)
public class Pessoa { public int PessoaId { get; set; } public string Nome { get; set; } public int CargoId { get; set; } public virtual Cargo { get; set; } }
public class Cargo { public int CargoId { get; set; } public string Nome { get; set; } public virtual ICollection Pessoas { get; private set; } }
So far, I have no doubts.
Now let's assume that I have a Room table and this room has a Manager, a supervisor and a person in charge, who are People. What would the relationship look like?
So:
public class Sala { public int SalaId { get; set; } public string Nome { get; set; } public int ResponsavelId { get; set; } public virtual Pessoa Responsavel {get; set; } public int SupervisorId { get; set; } public virtual Pessoa Supervisor {get; set; } public int GerenteId { get; set; } public virtual Pessoa Gerente {get; set; } }
And would change Person
public class Pessoa { public int PessoaId { get; set; } public string Nome { get; set; } public int CargoId { get; set; } public virtual Cargo { get; set; } public virtual ICollection Salas { get; private set; } }
And you would create the relationship in each field in the Fluent API with the Salas property or
public class Pessoa { public int PessoaId { get; set; } public string Nome { get; set; } public int CargoId { get; set; } public virtual Cargo { get; set; } public virtual ICollection SalaResponsavel { get; private set; } public virtual ICollection SalaSupervisor { get; private set; } public virtual ICollection SalaGerente { get; private set; } }