-2
I’m using the Entity Framework 6 and the Sqlserver. I have an object called category, where I want to persist it in the bank. and when I run this function, it persists the object correctly because I have a datagrid where I can observe that it worked. But when I close the application and search again the object is no longer there.
- Why does this happen?
- It is saved only at runtime and not persists?
I also noticed that the method Savechanges returns an integer, has something to indicate whether the insertion was right or wrong? for example, if returns 1 worked, if it is 0 wrong.
private void btnSalvar_Click(object sender, RoutedEventArgs e) { categoria objCategoria = new categoria(); objCategoria.Id = 0; objCategoria.descricao = ttbDescricao.Text; objCategoria.observacao = ttbObservacao.Text; objCategoria.status = 1; using (SiscabEntities SisEF = new SiscabEntities()) { //SisEF.categoria.Add(objCategoria); if (ttbCodigo.Text.Equals("")) { SisEF.Entry(objCategoria).State = EntityState.Added; } else { SisEF.Entry(objCategoria).State = EntityState.Modified; } SisEF.SaveChanges(); Inicializa(); } }
You have the option to answer your own question, do not put as an edit.
– Wictor Chaves