//Metodo eliminar public void Eliminar() { try { using (var db = new Model_Entity_1()) { db.Entry(this).State = EntityState.Deleted; db.SaveChanges(); } } catch (Exception ex) { throw; } }
//Metodo guardar public void Guardar() { try { using (var db = new Model_Entity_1()) { if (this.categoria_id > 0)//cuando la llave primaria es identity solamante { db.Entry(this).State = EntityState.Modified; } else { db.Entry(this).State = EntityState.Added; } db.SaveChanges(); } } catch (Exception ex) { throw; } }