Beispiel #1
0
        /// <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);
            }
        }
Beispiel #2
0
        /// <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);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 创建分页查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="query"></param>
        /// <param name="itemCount"></param>
        /// <param name="skipCount"></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
            {
                ((IPaging)query).Prefix("TOP " + itemCount);

                Field pagingField = query.PagingField;

                if ((IField)pagingField == null)
                {
                    throw new DataException("SqlServer2000或Access请使用SetPagingField设定分页主键!");
                }

                QuerySection <T> jquery = query.CreateQuery <T>();
                ((IPaging)jquery).Prefix("TOP " + skipCount);
                jquery.Select(pagingField);

                //sqlserver2000分页条件操作
                query.PageWhere = !pagingField.In(jquery);

                return(query);
            }
        }