예제 #1
0
        private static void ClearDb()
        {
            StudentsContext studentContext = new StudentsContext();

            DbSet <Mark> marks       = studentContext.Set <Mark>();
            List <Mark>  marksAsList = marks.ToList();

            foreach (Mark mark in marksAsList)
            {
                marks.Remove(mark);
            }

            DbSet <Student> students       = studentContext.Set <Student>();
            List <Student>  studentsAsList = studentContext.Set <Student>().ToList();

            foreach (Student student in studentsAsList)
            {
                students.Remove(student);
            }

            DbSet <School> schools       = studentContext.Set <School>();
            List <School>  schoolsAsList = schools.ToList();


            foreach (School school in schoolsAsList)
            {
                schools.Remove(school);
            }

            studentContext.SaveChanges();
        }