Exemplo n.º 1
0
        /// <summary>
        /// This method demonstrates how to undo the changes in Property level using DbContext.
        /// </summary>
        public static void UndoChangesInProperty()
        {
            using (DbMySchool school = new DbMySchool())
            {
                DbCourse     course     = school.DbCourses.FirstOrDefault();
                DbDepartment department = school.DbDepartments.FirstOrDefault();
                if (course != null)
                {
                    Console.WriteLine("Before changes:");
                    course.ShowDbCourse();

                    Console.WriteLine("After changes:");
                    // Change the course Properties.
                    course.Title     += "-Modified";
                    course.Department = department;
                    course.ShowDbCourse();

                    Console.WriteLine("After Undo Course Entity's Title Property:");
                    // Undo the change in the Entity Property level. UndoDbEntityProperty
                    // method will undo the Title property of the course, but the change of the
                    // Department Property will not be undone.
                    school.UndoDbEntityProperty(course, "Title");
                    course.ShowDbCourse();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// This method demonstrates how to undo the changes in Context level using DbContext.
        /// </summary>
        public static void UndoChangesInContext()
        {
            using (DbMySchool school = new DbMySchool())
            {
                DbCourse course = school.DbCourses.FirstOrDefault();
                if (course != null)
                {
                    Console.WriteLine("Before changes:");
                    course.ShowDbCourse();

                    Console.WriteLine("After changes:");
                    // Change the course and the related department.
                    course.Title           += "-Modified";
                    course.Department.Name += "-Modified";
                    course.ShowDbCourse();

                    Console.WriteLine("After Undo DbContext:");
                    // Undo the whole Context.
                    school.UndoDbContext();
                    course.ShowDbCourse();
                }
            }
        }