コード例 #1
0
 /// <summary>
 /// 更新;
 /// </summary>
 /// <param name="student">学生</param>
 /// <returns>受影响行数</returns>
 public static int Update(Student student)
 {
     using (var eduBase = EfHelper.GetDbContext())
     {
         eduBase.Entry(student).State = EntityState.Modified;
         return(eduBase.SaveChanges());
     }
 }
コード例 #2
0
 /// <summary>
 /// 添加;
 /// </summary>
 /// <param name="student">学生</param>
 /// <returns>受影响行数</returns>
 public static int Add(Student student)
 {
     using (var eduBase = EfHelper.GetDbContext())
     {
         eduBase.Student.Add(student);
         return(eduBase.SaveChanges());
     }
 }
コード例 #3
0
 /// <summary>
 /// 删除;
 /// </summary>
 /// <param name="studentNo">学号</param>
 /// <returns>受影响行数</returns>
 public static int Delete(string studentNo)
 {
     using (var eduBase = EfHelper.GetDbContext())
     {
         var student = eduBase.Student.Find(studentNo);
         eduBase.Student.Remove(student);
         return(eduBase.SaveChanges());
     }
 }
コード例 #4
0
 /// <summary>
 /// 查找所有班级;
 /// </summary>
 /// <returns>班级列表</returns>
 public static List <Class> FindAll()
 {
     using (var eduBase = EfHelper.GetDbContext())
     {
         var classes = from c in eduBase.Class
                       select c;
         return(classes.ToList());
     }
 }
コード例 #5
0
 /// <summary>
 /// 查找所有学院;
 /// </summary>
 /// <returns>学院列表</returns>
 public static List <Department> FindAll()
 {
     using (var eduBase = EfHelper.GetDbContext())
     {
         var departments = from d in eduBase.Department.Include("Major.Class")
                           select d;
         return(departments.ToList());
     }
 }
コード例 #6
0
 /// <summary>
 /// 查找学生;
 /// </summary>
 /// <param name="studentNo">学号</param>
 /// <returns>学生</returns>
 public static Student Find(string studentNo)
 {
     using (var eduBase = EfHelper.GetDbContext())
     {
         var student = from s in eduBase.Student
                       where s.No == studentNo
                       select s;
         return(student.FirstOrDefault());
     }
 }
コード例 #7
0
 /// <summary>
 /// 查找指定班级的学生;
 /// </summary>
 /// <param name="classNo">班级编号</param>
 /// <returns>学生简况列表</returns>
 public static List <StudentBasicInfo> FindByClassNo(int classNo)
 {
     using (var eduBase = EfHelper.GetDbContext())
     {
         var students = from s in eduBase.Student
                        where s.ClassNo == classNo
                        select new StudentBasicInfo {
             No = s.No, Name = s.Name
         };
         return(students.ToList());
     }
 }