示例#1
0
        private async Task UnEnrollSteveFromCourse(ManyToManyContext ctx)
        {
            StudentCourse steveAndDnp = ctx.Students.
                                        Where(s => s.StudentNum == 123456).
                                        SelectMany(student => student.StudentCourses).
                                        First(studentCourse => studentCourse.Course.CourseCode.Equals("IT-SDJ2-A20"));

            ctx.Remove(steveAndDnp);

            await ctx.SaveChangesAsync();
        }
示例#2
0
        private static async Task AddOneSteve(ManyToManyContext ctx)
        {
            Student s = new Student
            {
                FirstName  = "Steve",
                LastName   = "Doe",
                Email      = "*****@*****.**",
                StudentNum = 123456
            };
            await ctx.Students.AddAsync(s);

            await ctx.SaveChangesAsync();
        }
示例#3
0
        private static async Task EnrollSteveInDNP(ManyToManyContext ctx, string course)
        {
            Student steve = await ctx.Students.FirstAsync(s => s.StudentNum == 123456);

            Course dnp = await ctx.Courses.FirstAsync(c => c.CourseCode.Equals(course));

            StudentCourse sc = new StudentCourse
            {
                Course  = dnp,
                Student = steve
            };

            ctx.Set <StudentCourse>().Add(sc);
            await ctx.SaveChangesAsync();
        }
示例#4
0
        private static async Task AddTwoCourses(ManyToManyContext ctx)
        {
            Course sdj2 = new Course
            {
                Abbreviation = "SDJ2",
                Name         = "Software Development with UML and Java 2",
                Semester     = 2,
                CourseCode   = "IT-SDJ2-A20",
                ECTS         = 10
            };
            Course dnp1 = new Course
            {
                Abbreviation = "DNP1",
                Name         = "I forgot the actual name",
                Semester     = 3,
                CourseCode   = "IT-DNP1Y-A20",
                ECTS         = 5
            };
            await ctx.Courses.AddAsync(sdj2);

            await ctx.Courses.AddAsync(dnp1);

            await ctx.SaveChangesAsync();
        }