示例#1
0
    /// <summary>
    /// Shows how to Select all records by Course, related to column CourseName
    /// </summary>
    private void SelectCourseEnrollmentCollectionByCourseName()
    {
        int courseNameSample = 12;

        List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectCourseEnrollmentCollectionByCourseName(courseNameSample);

        // 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;
        }
    }
示例#2
0
    /// <summary>
    /// Shows how to Select all records by Course, related to column CourseName sorted by column name in either ascending or descending order.
    /// </summary>
    private void SelectCourseEnrollmentCollectionByCourseNameWithSortExpression()
    {
        int    courseNameSample = 12;
        string sortBy           = "EnrollmentId"; // ascending order
        //string sortBy = "EnrollmentId desc"; // descending order

        List <CourseEnrollment> objCourseEnrollmentCol = CourseEnrollment.SelectCourseEnrollmentCollectionByCourseName(courseNameSample, sortBy);
    }