示例#1
0
        //when to put context.saveChanges()?

        //seed students
        private void SeedStudents(AttendDBContext context)
        {
            context.Students.AddOrUpdate(
                p => p.StudentId,
                new Student {
                StudentId = "S01", FirstName = "Josh", LastName = "Knock"
            },
                new Student {
                StudentId = "S02", FirstName = "Marry", LastName = "Lee"
            }
                );
            context.SaveChanges();
        }
示例#2
0
 //seed student subjects
 private void SeedStudentSubjects(AttendDBContext context)
 {
     context.StudentSubjects.AddOrUpdate(
         new StudentSubject {
         StudentId = "S01", SubjectId = 1
     },
         new StudentSubject {
         StudentId = "S01", SubjectId = 2
     },
         new StudentSubject {
         StudentId = "S02", SubjectId = 3
     },
         new StudentSubject {
         StudentId = "S02", SubjectId = 8
     }
         );
     context.SaveChanges();
 }
示例#3
0
 //seed attendance
 private void SeedAttendaces(AttendDBContext context)
 {
     context.Attendances.AddOrUpdate(
         new Attendance {
         AttendanceId = 1, AttendanceDate = DateTime.Now, SubjectId = 1, StudentId = "S01", Present = true
     },
         new Attendance {
         AttendanceId = 2, AttendanceDate = DateTime.Now, SubjectId = 2, StudentId = "S01", Present = false
     },
         new Attendance {
         AttendanceId = 3, AttendanceDate = DateTime.Now, SubjectId = 3, StudentId = "S02", Present = true
     },
         new Attendance {
         AttendanceId = 4, AttendanceDate = DateTime.Now, SubjectId = 8, StudentId = "S02", Present = true
     }
         );
     context.SaveChanges();
 }
示例#4
0
 private void SeedSubjects(AttendDBContext context)
 {
     context.Subjects.AddOrUpdate(
         s => s.SubjectId,
         new Subject {
         SubjectName = "RAD"
     },
         new Subject {
         SubjectName = "Web"
     },
         new Subject {
         SubjectName = "Database"
     },
         new Subject {
         SubjectName = "Soft Prj Mgm"
     }
         );
     context.SaveChanges();
 }
示例#5
0
        //seed lectures and each lecture teaching one subject each
        private void SeedLectures(AttendDBContext context)
        {
            context.Lectures.AddOrUpdate(
                new Lecture {
                LectureId = 1, LectureName = "John K"
            },
                new Lecture {
                LectureId = 2, LectureName = "Kathy B"
            }
                );

            context.LectureSubjects.AddOrUpdate(
                new LectureSubject {
                LectureId = 1, SubjectId = 1
            },
                new LectureSubject {
                LectureId = 2, SubjectId = 8
            }
                );
            context.SaveChanges();
        }