0
When I make my insert
table companies field Empresacodigo (Field Identity) is going on insert
, even though his property is like Identity
in my application Asp.net.
What can I do ?
public class EmpresaController : System.Web.UI.Page
{
Entities context = new Entities();
public void Insert ()
{
empresa.EmpAtivo = empAtivo;
empresa.EmpData = empData;
empresa.EmpMF = empMF;
empresa.EmpRazao = empRazao;
empresa.EmpFantasia = fantasia;
empresa.EmpEndereco = empEndereco;
empresa.EmpNumero = empNumero;
empresa.EmpComp = empComp;
empresa.EmpBairro = empBairro;
empresa.EmpCidade = empCidade;
empresa.EmpEstado = empEstado;
empresa.EmpPais = empPais;
empresa.EmpCep = empCep;
empresa.EmpCNPJ = empCNPJ;
empresa.EmpIE = empIE;
empresa.EmpMunicipal = empMunicipal;
empresa.EmpCPF = empCPF;
empresa.EmpFone = empFone;
empresa.EmpCel = empCel;
empresa.EmpEmail = empEmail;
empresa.EmpMunicipio = empMunicipio;
empresa.EmpNire = empNire;
empresa.EmpCnae = empCnae;
empresa.EmpLogo = null;
empresa.EmpObs = empObs;
context.Empresas.Add(empresa);
context.SaveChanges();
}
}
I don’t understand "You’re going to the Insert". When a table has an Identity field, you do not need to include it explicitly, but you already know this and when you do Insert, it is fired. Even if there is rollback, for the case of transactions, even so it has already been fired, "burning" that value. Can explain better?
– pnet
Thank you very much for your availability, but I ended up here. In the database they created the field as Numeric, so I understood the visual studio was not recognizing that the field was Identity. I changed in the bank to int and model and worked normally.
– Otávio Medeiros
Nice that you thought.
– pnet