Ejemplo n.º 1
0
        public void RemoveStudentFromDB(Student toRemove)
        {
            var student = new Student {
                IdStudent = toRemove.IdStudent
            };

            //  context.Entry(stu).State = System.Data.Entity.EntityState.Modified;
            var entry = context.Entry(student);

            /*  if (entry.State == EntityState.Detached || entry.State == EntityState.Modified)
             * {
             *     context.Entry(stu).State = System.Data.Entity.EntityState.Detached;
             *    entry.State = EntityState.Modified;
             */
            context.Students.Attach(student);
            context.Students.Remove(student);
            context.SaveChanges();
        }
Ejemplo n.º 2
0
        public void Commit()
        {
            bool saveFailed;

            do
            {
                saveFailed = false;
                try
                {
                    context.SaveChanges();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    saveFailed = true;


                    ex.Entries.Single().Reload();
                }
            } while (saveFailed);
        }