Following its line of reasoning, an internal Ncsoaint may be related in one Ncunit as a person Terna and the other Ncunit as a manager. So that means that the internal Ncpeopleclass can have more than 1 Ncunit and Ncunit can have more than 1 internal Ncpeople1, whether you are the manager or not.
Then we have an N-N relationship between the classes, so a new class should be created that calls table-relatedness, it will make the relationship between the Inner Person and Unity.
In Ncpesint change the Unit property:
public List<NcPessoaInternaUnidade> Unidades { get; private set; }
In Ncunidade exchange the Personal and Management properties for:
public List<NcPessoaInternaUnidade> PessoaInternas { get; private set; }
Create the relationship class:
public class NcPessoaInternaUnidade {
public int Id { get; set; }
public NcPessoaInterna PessoaInterna { get; set; }
public int PessoaInternaId { get; set; }
public NcUnidade Unidade { get; set; }
public int UnidadeId { get; set; }
public bool Gestor { get; set; }
}
Use the boolean Manager property to declare if Ncpesintern is a manager (true) or if it is an internal person (false) in an Ncunit.
Redo fluent API this way:
//Relacionamento NcPessoaInternaUnidade - NcPessoaInterna
modelBuilder.Entity<NcPessoaInternaUnidade>()
.HasOne(p => p.PessoaInterna)
.WithMany(b => b.Unidades)
.HasForeignKey(p => p.PessoaInternaId);
//Relacionamento NcPessoaInternaUnidade - NcUnidade
modelBuilder.Entity<NcPessoaInternaUnidade>()
.HasOne(p => p.Unidade)
.WithMany(b => b.PessoaInternas)
.HasForeignKey(p => p.UnidadeId);
I hope I’ve helped.
hello Luan, avoid images and put the text is better to view
– Ricardo Pontual