I made this method and other attempts. With the table filled, okay, but with the table without data, it is giving error:
public int GeraIdBalanca()
{
int chave = 0;
var obj = contexto.Balancas.Max().IdBalanca;
if (obj == 0)
chave = 1;
else
chave = obj + 1;
return chave;
}
I tried the table with information, I can bring the ID, but with the table zeroed, newly created gives me error.