Ejemplo n.º 1
0
 public bool CreateStudent(string name, string surname, string clas)
 {
     using (var SC = new DAL.Model.MVC_Sc())
     {
         Student S = new Student();
         S = addStudent(name, surname);
         var          C     = SC.Classes.Where(z => z.Name == clas).FirstOrDefault();
         StudentClass SClas = new StudentClass();
         SClas.ClassId   = C.Id;
         SClas.StudentId = S.Id;
         SC.StudentClasses.Add(SClas);
         SC.SaveChanges();
         return(true);
     }
 }
        /// <summary>
        /// 根据班级Id查询学生列表
        /// </summary>
        /// <param name="studentClass"></param>
        /// <returns></returns>
        public List <StudentExt> QueryStudentsByClassId(StudentClass studentClass)
        {
            string sql = "select StudentId,StudentName,Gender,Birthday,b.ClassId,ClassName from";

            sql += " Students a inner join StudentClass b on a.ClassId=b.ClassId where b.ClassId={0}";
            sql  = string.Format(sql, studentClass.ClassId);
            List <StudentExt> studentList = new List <StudentExt>();
            SqlDataReader     reader      = SQLHelper.GetReader(sql);

            while (reader.Read())
            {
                studentList.Add(new StudentExt
                {
                    StudentId   = Convert.ToInt32(reader["StudentId"]),
                    StudentName = reader["StudentName"].ToString(),
                    Gender      = reader["Gender"].ToString(),
                    Birthday    = Convert.ToDateTime(reader["Birthday"]),
                    ClassId     = Convert.ToInt32(reader["StudentId"]),
                    ClassName   = reader["ClassName"].ToString(),
                });
            }
            reader.Close();
            return(studentList);
        }