2
I’m having trouble saving in a relationship of many to many, follows my model:
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 scheme of Migrations works perfectly, but would like to know when to save the data in the table pessoa
and table conta
already insert the respective values in the table pessoaConta
. From now on I thank you all.
solved temporarily, but the following problem appeared. it would be possible when you already have the account and the registered person to link the data in table N-N
– Thiago Ubiratan
There you have to map manual. See more here.
– Leonel Sanches da Silva