public static void Delete(int?id) { using (dbpeliculasEntities db = new dbpeliculasEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { tblPelicula pelicula = db.tblPelicula.Find(id); db.Entry(pelicula).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw; } } } }
public static void Update(tblPelicula pelicula) { using (dbpeliculasEntities db = new dbpeliculasEntities()) { using (var transaction = db.Database.BeginTransaction()) { try { db.tblPelicula.Attach(pelicula); db.Entry(pelicula).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); throw ex; } } } }