public static void Initialize(ClassStudentDbContext context)
        {
            //context.Database.EnsureCreated();


            if (context.ClassRooms.Any())
            {
                return;
            }

            var rooms = new ClassRoom[]
            {
                new ClassRoom
                {
                    ClassName   = "Biology",
                    Location    = "Building 5 Room",
                    TeacherName = "Mr Robertson",
                    Students    = new List <Student>()
                    {
                        new Student
                        {
                            StudentName = "David Jackson",
                            Age         = 19,
                            Gpa         = 3.4
                        },
                        new Student
                        {
                            StudentName = "Peter Parker",
                            Age         = 19,
                            Gpa         = 3.2
                        },
                        new Student
                        {
                            StudentName = "Robert Smit",
                            Age         = 19,
                            Gpa         = 1.2
                        },
                    }
                }
            };

            context.ClassRooms.AddRange(rooms);
            context.SaveChanges();
        }
예제 #2
0
 public IndexModel(ClassStudentDbContext context)
 {
     _context = context;
 }
 public EditModel(ClassStudentDbContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }