/// <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()); } }
/// <summary> /// 查找指定页码的所有学生; /// </summary> /// <param name="pageIndex">页码</param> /// <returns>学生绑定列表</returns> public IEnumerable <Student> FindAll(int pageIndex) { this.EduBase = EfHelper.GetDbContext(); var students = from s in this.EduBase.Student orderby s.No ascending select s; int previousRowCount = (pageIndex - 1) * this.PageSize; var studentsPage = students.Skip(previousRowCount).Take(this.PageSize); studentsPage.Load(); return(this.EduBase.Student.Local.ToBindingList()); }
/// <summary> /// 初始化数据库; /// </summary> /// <returns></returns> public static bool InitDb() { using (var eduBase = EfHelper.GetDbContext()) { if (eduBase.Database.Exists()) { eduBase.Database.ExecuteSqlCommand("SELECT pg_terminate_backend(A.pid) FROM pg_stat_activity AS A WHERE A.datname='EduBaseDemo' AND A.pid<>pg_backend_pid();"); } eduBase.Database.Delete(); return(eduBase.Database.CreateIfNotExists()); } }
/// <summary> /// 构造函数; /// </summary> public StudentRepository() { this.EduBase = EfHelper.GetDbContext(); this.PageSize = 6; }