Esempio n. 1
0
        public void GetAllStudentsPerCourses(School school)
        {
            SqlCommand    cmdStudentPerCourse      = new SqlCommand("SELECT * FROM StudentPerCourse", sqlConnection);
            SqlDataReader readerStudentsPerCourses = cmdStudentPerCourse.ExecuteReader();

            while (readerStudentsPerCourses.Read())
            {
                // ONE FROM THE STUDENTS WITH LINQ
                Student student = school.Students.SingleOrDefault(s => s.ID == readerStudentsPerCourses.GetInt32(0));
                //ONE FROM THE COURSES WITH LINQ
                Course course = school.Courses.SingleOrDefault(c => c.ID == readerStudentsPerCourses.GetInt32(1));
                var    newStudentPerCourse = new StudentPerCourse(student, course);
                student.Courses.Add(newStudentPerCourse);
                course.Students.Add(newStudentPerCourse);
                school.StudentsPerCourses.Add(newStudentPerCourse);
            }

            readerStudentsPerCourses.Close();

            //var newLista = school.StudentsPerCourses.Select(spc => $"Course is  : {spc.Course} and student is : {spc.Student}").ToList();
        }
Esempio n. 2
0
 public void AddStudentPerCourse(StudentPerCourse studentPerCourse)
 {
     StudentsPerCourses.Add(studentPerCourse);
 }