コード例 #1
0
        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();
        }
コード例 #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.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);

            studentDBContext.Students.FirstOrDefault(x => x.StudentID == 1).Courses.Add(WCFCourse);
            studentDBContext.SaveChanges();

        }
コード例 #4
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.FirstOrDefault(x => x.StudentID == 2).Courses.Remove(SQLServerCourse);
            studentDBContext.SaveChanges();



        }
コード例 #5
0
        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();
        }
コード例 #6
0
        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();
        }