I'm having trouble saving in a many-to-many relationship, follow my template:
public class Pessoa
{
public int id { get; set; }
public string descricao { get; set; }
public ICollection<Conta> Conta { get; set; }
}
public class Conta
{
public int id { get; set; }
public string descricao { get; set; }
public ICollection<Pessoa> Pessoa { get; set; }
}
Here is the setting in my context for n-n:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Pessoa>()
.HasMany<Conta>(x => x.Conta)
.WithMany(x => x.Pessa)
.Map(x =>
{
x.ToTable("PessoaConta");
x.MapLeftKey("pessoaId");
x.MapRightKey("contaId");
});
base.OnModelCreating(modelBuilder);
}
So far so good: my migrations scheme works perfectly, but I would like to know when to save the data in the pessoa
table and the conta
table already insert the respective values in the% . Thanks in advance.