/// <summary> /// Shows how to Select all records. It also shows how to sort, bind, and loop through records. /// </summary> private void SelectAll() { // select all records List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectAll(); // Example 1: you can optionally sort the collection in ascending order by your chosen field objCourseEnrollmentCol.Sort(CourseEnrollment.ByCourseName); // Example 2: to sort in descending order, add this line to the Sort code in Example 1 objCourseEnrollmentCol.Reverse(); // Example 3: directly bind to a GridView - for ASP.NET Web Forms // GridView grid = new GridView(); // grid.DataSource = objCourseEnrollmentCol; // grid.DataBind(); // Example 4: loop through all the CourseEnrollment(s) foreach (CourseEnrollment objCourseEnrollment in objCourseEnrollmentCol) { int enrollmentId = objCourseEnrollment.EnrollmentId; int courseName = objCourseEnrollment.CourseName; int studentName = objCourseEnrollment.StudentName; string comments = objCourseEnrollment.Comments; // get the Course related to CourseName. Course objCourseRelatedToCourseName = objCourseEnrollment.CourseNameNavigation; // get the Student related to StudentName. Student objStudentRelatedToStudentName = objCourseEnrollment.StudentNameNavigation; } }
/// <summary> /// Shows how to Select all records sorted by column name in either ascending or descending order. /// </summary> private void SelectAllWithSortExpression() { // select all records sorted by EnrollmentId in ascending order string sortBy = "EnrollmentId"; // ascending order //string sortBy = "EnrollmentId desc"; // descending order List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectAll(sortBy); }