1
I made this method and other attempts. With the table filled, ok, 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 with the table with information, I can bring the ID, but with the table reset, newly created gives me error.
I can not say because I think that it lacks context (without wanting to make pun with the variable), but this code can be written like this:
contexto.Balancas.Max().IdBalanca + 1
and gives the same result.– Maniero
if there is no record in the bank,
Max()
would return null ?– Rovann Linhalis