//metodo Eliminar public void Eliminar() { try { using (var db = new Model_Sistema()) { db.Entry(this).State = EntityState.Deleted; db.SaveChanges(); } } catch (Exception ex) { throw; } }
//metodo guardar public void Guardar()//retorna solo un objeto { try { using (var db = new Model_Sistema()) { if (this.semestre_id > 0) { //si existe un valor mayor a 0 es porque existe un registro db.Entry(this).State = EntityState.Modified; } else { //si no existe registro graba(nuevo registro) db.Entry(this).State = EntityState.Added; } db.SaveChanges(); } } catch (Exception ex) { throw; } }