I'm trying to make a table relationship, 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 Company x Manager relationship, I came up with 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.