protected void Button1_Click(object sender, EventArgs e) { StudentDBContext studentDBContext = new StudentDBContext(); Course WCFCourse = studentDBContext.Courses.FirstOrDefault(x => x.CourseID == 4); studentDBContext.Students.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.FirstOrDefault(x => x.StudentID == 2).Courses.Remove(SQLServerCourse); studentDBContext.SaveChanges(); }
protected void Page_Load(object sender, EventArgs e) { StudentDBContext studentDBContext = new StudentDBContext(); //using LINQ GridView1.DataSource = (from student in studentDBContext.Students from course in student.Courses select new { StudentName = student.StudentName, CourseName = course.CourseName }).ToList(); GridView1.DataBind(); }