コード例 #1
0
 public static void ClearData(this UniversityResidenceDbContext context)
 {
     context.Employees.RemoveAll();
     context.Halls.RemoveAll();
     context.Rooms.RemoveAll();
     context.Students.RemoveAll();
     context.SaveChanges();
 }
コード例 #2
0
        // not perfect, if you get an error, clear and try again
        public static void GenerateData(this UniversityResidenceDbContext context)
        {
            var halls    = GenerateHalls();
            var rooms    = GenerateRooms(halls, 30);
            var students = GenerateStudents(rooms);
            var emplyees = GenerateEmployees(halls, 10);

            halls.ForEach(h => context.Halls.Add(h));
            rooms.ForEach(r => context.Rooms.Add(r));
            students.ForEach(s => context.Students.Add(s));
            emplyees.ForEach(e => context.Employees.Add(e));
            context.SaveChanges();
        }