/// <summary> /// 添加学生的方法 /// </summary> /// <param name="stu"></param> /// <returns></returns> public int InsertStudent(Student stu) { SchoolEntities entity = new SchoolEntities(); entity.Student.Add(stu); int count = entity.SaveChanges(); return(count); }
/// <summary> /// 删除学生 /// </summary> /// <param name="studentNo"></param> /// <returns></returns> public int DeleteStudent(string studentNo) { int count = 0; SchoolEntities entity = new SchoolEntities(); Student deleteStudent = (from a in entity.Student where a.StudentNo == studentNo select a).FirstOrDefault(); //判断该学生是否有关联的成绩数据 if (deleteStudent.Result.Count() > 0) { count = -1; } else { entity.Student.Remove(deleteStudent); count = entity.SaveChanges(); } return(count); }
/// <summary> /// 修改学生的方法 /// </summary> /// <param name="stu"></param> /// <returns></returns> public int UpdateStudent(Student stu) { SchoolEntities entity = new SchoolEntities(); Student upStu = (from a in entity.Student where a.StudentNo == stu.StudentNo select a).FirstOrDefault(); int count = 0; if (upStu != null) { upStu.StudentName = stu.StudentName; upStu.Address = stu.Address; upStu.BornDate = stu.BornDate; upStu.Email = stu.Email; upStu.GradeId = stu.GradeId; upStu.LoginPwd = stu.LoginPwd; upStu.Phone = stu.Phone; upStu.Sex = stu.Sex; count = entity.SaveChanges(); } return(count); }