Good afternoon!
I have this many-to-many configuration in my project.
public class Usuario
{
public Usuario()
{
this.LocalTrabalho = new HashSet<LocalAtendimento>();
}
public virtual ICollection<LocalAtendimento> LocalTrabalho { get; set; }
}
public class LocalTrabalho
{
public LocalTrabalho ()
{
this.Usuarios = new HashSet<Usuario>();
}
public virtual ICollection<Usuario> Usuarios{ get; set; }
}
modelBuilder.Entity<LocalAtendimento>()
.HasMany<Usuario>(s => s.Usuarios)
.WithMany(c => c.LocalTrabalho)
.Map(cs =>
{
cs.MapLeftKey("LocalTrabalho_Seq");
cs.MapRightKey("Usuario_Seq");
cs.ToTable("LocalTrabalhoUsuario");
});
When I save a user it should only reference the work place, but when saving it creates a new work place in the working place table, with the same data of the referenced workplace, does anyone know how to solve it?
Thank you.