Show / Hide Table of Contents

    Model Class: CourseInfo.cs

    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using SnapObjects.Data;
    using Newtonsoft.Json;
    using System.Collections.Generic;
    
    namespace Appeon.ApiDoc.Models.School
    {
        /// <summary>
        /// This model class maps to the dbo.Course table. 
        /// It uses the primary key to generate the Where clause for the Update operation.
        /// The SqlParameter attribute defines an argument: deptId.
        /// The SqlWhere attribute defines the SQL Where clause using the deptId argument.
        /// 
        /// CourseID is the primary key.
        /// 
        /// The Students property is applied with the ModelEmbedded attribute.
        /// It defines the one-to-more relationship between the course and the students 
        /// who selected the course.
        /// 
        /// The Instructors property is applied with the ModelEmbedded attribute.
        /// It defines the one-to-more relationship between the course and the instructors.
        /// 
        /// The OnlineFlag property is applied with the SqlEmbedded attribute.
        /// It defines how to get the online flag using a raw SQL Select.
        /// </summary>
        [SqlParameter("deptId", typeof(int))]
        [Table("Course", Schema = "dbo")]
        [UpdateWhereStrategy(UpdateWhereStrategy.KeyColumns)]
        [SqlWhere("DepartmentId = :deptId")]
        [SqlSelect("SelectCourse", RawSelect = "Title")]
        public class CourseInfo
        {
            [Key]
            public int CourseID { get; set; }
    
            public string Title { get; set; }
    
            public int Credits { get; set; }
    
            public int DepartmentID { get; set; }
    
            // Students who selected this course.
            [JsonIgnore]
            [SetValue("$CourseID", "$CourseID", SetValueStrategy.Always)]
            [ModelEmbedded(typeof(CourseStudentInfo), ParamValue = "$CourseID",
                CascadeCreate = true, CascadeDelete = true)]
            public IList<CourseStudentInfo> Students { get; set; }
    
            // Instructors of this course.
            [JsonIgnore]
            [SetValue("$CourseID", "$CourseID", SetValueStrategy.Always)]
            [ModelEmbedded(typeof(CourseInstructorInfo), ParamValue = "$CourseID",
                CascadeCreate = true, CascadeDelete = true)]
            public IList<CourseInstructorInfo> Instructors { get; set; }
    
            // Online course flag.
            [JsonIgnore]
            [SqlEmbedded(@"SELECT Count(1) 
                            FROM OnlineCourse 
                            WHERE CourseID = @id",
                         ParamValue = "$CourseID")]
            public int OnlineFlag { get; set; }
    
        }
    }
    
    Back to top Generated by Appeon