static void CreateStaff(SchoolContext context) { context.AddRange(new List <Staff>() { new Staff() { Name = "Nicola", Email = "*****@*****.**", JobTitle = "Lecturer" }, new Staff() { Name = "Saurabh", Email = "*****@*****.**", JobTitle = "Associate Professor" }, new Staff() { Name = "Lindsay", Email = "*****@*****.**", JobTitle = "Tutor" }, new Staff() { Name = "Michael", Email = "*****@*****.**", JobTitle = "Tutor" } }); }
private void SetTeacher() { var s = SchoolContext.Subjects.ToList(); var t1 = new Teacher { Name = "teacher1", }; t1.Subjects.Add(s[0]); var t2 = new Teacher { Name = "teacher2", }; t1.Subjects.Add(s[2]); t1.Subjects.Add(s[1]); var t3 = new Teacher { Name = "teacher3", }; t1.Subjects.Add(s[2]); SchoolContext.AddRange(t1, t2, t3); SchoolContext.SaveChanges(); }
static void CreateSubjects(SchoolContext context) { context.AddRange(new List <Subject>() { new Subject() { Code = "PRG101", Name = "Introduction to Programming", Description = "A first look at basic programming techniques.", }, new Subject() { Code = "PRG102", Name = "Data Structures and Algorithms", Description = "Covers core concepts related to algorithmic problem solving and common data structures.", }, new Subject() { Code = "PRG201", Name = ".NET Application Development", Description = "Desktop application development using Microsoft's .NET platform.", }, new Subject() { Code = "PRG301", Name = "Advanced Algorithms", Description = "A more in-dept focus on complex algoriths and related techniques.", }, }); }
static void CreateStudents(SchoolContext context) { context.AddRange(new List <Student>() { new Student() { Name = "Liam", Email = "*****@*****.**", Degree = "Bachelor of Science" }, new Student() { Name = "Sam", Email = "*****@*****.**", Degree = "Bachelor of Arts" }, new Student() { Name = "Jess", Email = "*****@*****.**", Degree = "Bachelor of Computer Science" }, new Student() { Name = "Sylvia", Email = "*****@*****.**", Degree = "Bachelor of Engineering" }, new Student() { Name = "Darell", Email = "*****@*****.**", Degree = "Bachelor of Computer Science" }, new Student() { Name = "Lucia", Email = "*****@*****.**", Degree = "Bachelor of IT" }, new Student() { Name = "Han", Email = "*****@*****.**", Degree = "Bachelor of Computer Science" }, new Student() { Name = "Alex", Email = "*****@*****.**", Degree = "Bachelor of Science" }, }); }
static async Task Main(string[] args) { var context = new SchoolContext(); // deleted previous var deleted = await context.Database.EnsureDeletedAsync().ConfigureAwait(false); // creating an empty one var created = await context.Database.EnsureCreatedAsync().ConfigureAwait(false); if (deleted && created) { // seed some data var firstStudent = new Student { Name = "Usman" }; var secondStudent = new Student { Name = "Haider" }; var firstCourse = new Course { Title = "First", Students = new List <Student> { firstStudent } }; var secondCourse = new Course { Title = "Second", Students = new List <Student> { secondStudent } }; //var firstStudentCourse = new StudentCourse { Student = firstStudent, Course = firstCourse }; //var secondStudentCourse = new StudentCourse { Student = secondStudent, Course = secondCourse }; context.AddRange(firstCourse, secondCourse); _ = await context.SaveChangesAsync(); var results = await context.Students.Where(x => x.Cources.Any(sc => sc.Title == "Second")).ToListAsync(); foreach (var result in results) { Console.WriteLine($"{result.Name}"); } var results1 = await context.Students.Where(x => x.StudentCourses.Any(sc => sc.Course.Title == "Second")).ToListAsync(); foreach (var result in results1) { Console.WriteLine($"{result.Name}"); } } Console.WriteLine("End of program"); }
private void SetCabinetes() { var c1 = new Cabinete { Id = Guid.NewGuid().ToString(), Name = "1" }; var c2 = new Cabinete { Id = Guid.NewGuid().ToString(), Name = "2" }; var c3 = new Cabinete { Id = Guid.NewGuid().ToString(), Name = "3" }; SchoolContext.AddRange(c1, c2, c3); SchoolContext.SaveChanges(); }
private void SetClass() { var c1 = new Class { Id = Guid.NewGuid().ToString(), Grade = 1, Litera = 'a' }; var c2 = new Class { Id = Guid.NewGuid().ToString(), Grade = 2, Litera = 'b' }; var c3 = new Class { Id = Guid.NewGuid().ToString(), Grade = 3, Litera = 'c' }; SchoolContext.AddRange(c1, c2, c3); SchoolContext.SaveChanges(); }
private void SetSubject() { var s1 = new Subject { Id = Guid.NewGuid().ToString(), MaxPerWeek = 10, Name = "Biology" }; var s2 = new Subject { Id = Guid.NewGuid().ToString(), MaxPerWeek = 20, Name = "Literatura" }; var s3 = new Subject { Id = Guid.NewGuid().ToString(), MaxPerWeek = 10, Name = "It" }; SchoolContext.AddRange(s1, s2, s3); SchoolContext.SaveChanges(); }
static void CreateClasses(SchoolContext context) { var prg101 = context.Subjects.Single(s => s.Code == "prg101"); var prg102 = context.Subjects.Single(s => s.Code == "prg102"); var prg201 = context.Subjects.Single(s => s.Code == "prg201"); var lecturer = context.Staffs.First(s => s.JobTitle == "Lecturer"); var tutor = context.Staffs.First(s => s.JobTitle == "Tutor"); context.AddRange(new List <Lesson>() { new Lesson() { Subject = prg101, Teacher = tutor, StartTime = "TUE 09:00", EndTime = "TUE 10:00", RoomNumber = "K30", LessonType = LessonType.Tutorial }, new Lesson() { Subject = prg101, Teacher = lecturer, StartTime = "THU 10:00", EndTime = "THU 11:00", RoomNumber = "L35", LessonType = LessonType.Lecture }, new Lesson() { Subject = prg101, Teacher = lecturer, StartTime = "THU 12:00", EndTime = "THU 13:00", RoomNumber = "L35", LessonType = LessonType.Lecture }, new Lesson() { Subject = prg101, Teacher = lecturer, StartTime = "FRI 11:00", EndTime = "FRI 12:00", RoomNumber = "L18", LessonType = LessonType.Lecture }, new Lesson() { Subject = prg102, Teacher = lecturer, StartTime = "MON 10:00", EndTime = "MON 12:00", RoomNumber = "L33", LessonType = LessonType.Lecture }, new Lesson() { Subject = prg102, Teacher = lecturer, StartTime = "WED 15:00", EndTime = "WED 16:00", RoomNumber = "L35", LessonType = LessonType.Lecture }, new Lesson() { Subject = prg102, Teacher = tutor, StartTime = "THU 12:00", EndTime = "THU 13:00", RoomNumber = "M20", LessonType = LessonType.Tutorial }, new Lesson() { Subject = prg201, Teacher = lecturer, StartTime = "TUE 11:00", EndTime = "TUE 12:00", RoomNumber = "L33", LessonType = LessonType.Lecture }, new Lesson() { Subject = prg201, Teacher = lecturer, StartTime = "WED 15:00", EndTime = "WED 16:00", RoomNumber = "L33", LessonType = LessonType.Lecture }, new Lesson() { Subject = prg201, Teacher = tutor, StartTime = "THU 12:00", EndTime = "THU 13:00", RoomNumber = "M22", LessonType = LessonType.Tutorial }, new Lesson() { Subject = prg201, Teacher = tutor, StartTime = "FRI 14:00", EndTime = "FRI 17:00", RoomNumber = "M16", LessonType = LessonType.Lab }, }); }
public async Task UpdateDBAsync(IList <School> schools) { _context.AddRange(schools); await _context.SaveChangesAsync(); }