1
I am trying to make a relationship of tables, using Fluentapi with Entity Framework, in which my purpose are 3 entities:
public class Empresa
{
public Empresa()
{
this.Gerentes = new HashSet<Gerente>();
}
public int EmpresaId { get; set; }
public string EmpresaNome { get; set; }
public virtual ICollection<Gerente> Gerentes { get; set; }
}
public class Gerente
{
public Gerente()
{
this.Empresas = new HashSet<Empresa>();
}
public int GerenteId { get; set; }
public string GerenteNome { get; set; }
public virtual ICollection<Empresa> Empresas { get; set; }
}
public class Projeto
{
public int ProjetoId { get; set; }
public string ProjetoNome { get; set; }
}
Problem:
A manager can be a manager in more than one company, but a project only belongs to a manager in the specific company.
About the relationship Company x Manager, I reached this result:
modelBuilder.Entity<Empresa>()
.HasMany<Gerente>(s => s.Gerentes)
.WithMany(c => c.Empresas)
.Map(cs =>
{
cs.MapLeftKey("EmpresaId");
cs.MapRightKey("GerenteId");
cs.ToTable("EmpresaGerente");
});
Now my problem is how to relate the project to the manager in that company.
Relate the projects to your company and when linking the manager to the project, validate if they are from the same company.
– G. M4rc14L