protected void Button1_Click(object sender, EventArgs e)
        {
            StudentDBContext studentDBContext = new StudentDBContext();

            Course WCFCourse = studentDBContext.Courses.FirstOrDefault(x => x.CourseID == 4);
            //by using the include method becuase it is load all the related entityies - this is called lazy loading.
            studentDBContext.Students.Include("Courses").FirstOrDefault(x => x.StudentId == 1).Courses.Add(WCFCourse);
            studentDBContext.SaveChanges();
        }
예제 #2
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            StudentDBContext studentDBContext = new StudentDBContext();
            //Find the Course
            Course SQLServerCourse = studentDBContext.Courses.FirstOrDefault(x => x.CourseID == 3);

            // Get John and Remove John from the SQL SERVER Course = 3
            studentDBContext.Students.Include("Courses").FirstOrDefault(x => x.StudentId == 2).Courses.Remove(SQLServerCourse);
            studentDBContext.SaveChanges();
        }
예제 #3
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            StudentDBContext studentDBContext = new StudentDBContext();

            Course WCFCourse = studentDBContext.Courses.FirstOrDefault(x => x.CourseID == 4);

            //by using the include method becuase it is load all the related entityies - this is called lazy loading.
            studentDBContext.Students.Include("Courses").FirstOrDefault(x => x.StudentId == 1).Courses.Add(WCFCourse);
            studentDBContext.SaveChanges();
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            StudentDBContext studentDBContext = new StudentDBContext();
            //Find the Course
            Course SQLServerCourse = studentDBContext.Courses.FirstOrDefault(x => x.CourseID == 3);

            // Get John and Remove John from the SQL SERVER Course = 3
            studentDBContext.Students.Include("Courses").FirstOrDefault(x => x.StudentId == 2).Courses.Remove(SQLServerCourse);
            studentDBContext.SaveChanges();
        }