1
I am implementing a Web Api and I am using EF Core in the infrared layer. I have the related entities Table and Tableprecoitem, I wonder if to increment the property Tableprecoitem of an entity Table that is already saved, I need to do some specific configuration?
I’m doing like this:
public override void Add(TabelaPreco tabela)
{
if (_dbSet.Any(tb => tb.Id == tabela.Id))
{
var table = _dbSet.Where(tb => tb.Id == tabela.Id)
.Include(tbi => tbi.Items).First();
table.Items = tabela.Items;
_dbSet.Update(table);
}
else
{
_dbSet.Add(tabela);
}
_context.SaveChanges();
}
No Typeconfiguration
builder.HasMany(p => p.Items)
.WithOne(itens => itens.TabelaPreco)
.HasForeignKey(fk => fk.TabelaPrecoId);