/// <summary> /// 加载分页列表 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="pageIndex">当前页码</param> /// <param name="pageSize">每页条数</param> /// <param name="recordCount">记录总数</param> /// <param name="where">查询条件</param> /// <param name="orderBy">排序字段</param> /// <param name="dbSort">正序或倒序</param> /// <returns>实体列表,输出记录总数</returns> public List <T> PageList <T>(int pageIndex, int pageSize, out int recordCount, Expression <Func <T, bool> > where = null, Expression <Func <T, object> > orderBy = null, MyDbSort dbSort = MyDbSort.Asc) where T : class, new() { var query = new MyQueryable <T>(_connectionString); if (where != null) { query.Where(where); } if (orderBy != null) { if (dbSort == MyDbSort.Desc) { query.OrderByDesc(orderBy); } else { query.OrderBy(orderBy); } } return(query.ToPageList(pageIndex, pageSize, out recordCount)); }
/// <summary> /// 根据条件加载一个实体 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="where">查询条件</param> /// <param name="orderBy">排序字段</param> /// <param name="dbSort">正序或倒序</param> /// <returns>实体,若记录为空,返回default(T)</returns> public T Load <T>(Expression <Func <T, bool> > where = null, Expression <Func <T, object> > orderBy = null, MyDbSort dbSort = MyDbSort.Asc) where T : class, new() { var query = new MyQueryable <T>(_connectionString); if (where != null) { query.Where(where); } if (orderBy != null) { if (dbSort == MyDbSort.Desc) { query.OrderByDesc(orderBy); } else { query.OrderBy(orderBy); } } return(query.FirstOrDefault()); }