/// <summary> /// 创建分页查询 /// </summary> /// <param name="query"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> protected internal override QuerySection <T> CreatePageQuery <T>(QuerySection <T> query, int itemCount, int skipCount) { if (skipCount == 0) { ((IPaging)query).Prefix("TOP " + itemCount); return(query); } else { //如果没有指定Order 则由指定的key来排序 if (string.IsNullOrEmpty(query.OrderString)) { Field pagingField = query.PagingField; if ((IField)pagingField == null) { throw new DataException("请指定分页主键或设置排序!"); } query.OrderBy(pagingField.Asc); } ((IPaging)query).Suffix(",ROW_NUMBER() OVER(" + query.OrderString + ") AS TMP__ROWID"); query.OrderBy(OrderByClip.None); query.SetPagingField(null); QuerySection <T> jquery = query.SubQuery("TMP_TABLE"); jquery.Where(new WhereClip("TMP__ROWID BETWEEN " + (skipCount + 1) + " AND " + (itemCount + skipCount))); jquery.Select(Field.All.At("TMP_TABLE")); return(jquery); } }
/// <summary> /// 创建分页查询 /// </summary> /// <param name="query"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> protected internal override QuerySection <T> CreatePageQuery <T>(QuerySection <T> query, int itemCount, int skipCount) { if (skipCount == 0) { ((IPaging)query).Prefix("top " + itemCount); return(query); } else { //如果没有指定Order 则由指定的key来排序 if (query.OrderString == null) { Field pagingField = query.PagingField; if ((IField)pagingField == null) { throw new MySoftException("请指定分页主键或设置排序!"); } query.OrderBy(pagingField.Asc); } ((IPaging)query).Suffix(",row_number() over(" + query.OrderString + ") as tmp__rowid"); query.OrderBy(OrderByClip.Default); QuerySection <T> jquery = query.SubQuery("tmp_table"); jquery.Where(new WhereClip("tmp__rowid between " + (skipCount + 1) + " and " + (itemCount + skipCount))); jquery.Select(Field.All.At("tmp_table")); return(jquery); } }