public void Eliminar(int id) { try { using (var ctx = new TestContex()) { ctx.Entry(new Alumno { Id = id }).State = EntityState.Deleted; ctx.SaveChanges(); } } catch (Exception) { throw; } }
public void Guardar(Alumno alumno) { try { using (var ctx = new TestContex()) { //Regitro que ya existe if (alumno.Id > 0) { ctx.Entry(alumno).State = EntityState.Modified; } else { ctx.Entry(alumno).State = EntityState.Added; } ctx.SaveChanges(); } } catch (Exception) { throw; } }