//public bool NeedOrderBy()
        //{
        //    if (_sortList.Count == 0 && _adapter is SqlserverAdapter)
        //    {
        //        return true;
        //    }
        //    return false;
        //}

        public string QueryPage(int pageSize, int?pageNumber = null)
        {
            SqlEntity entity = GetSqlEntity();

            entity.PageSize = pageSize;
            if (pageNumber.HasValue)
            {
                if (_sortList.Count == 0 && _adapter is SqlserverAdapter)
                {
                    var key = _columnDefines.FirstOrDefault(p => p.KeyAttribute != null);
                    if (key == null)
                    {
                        key = _columnDefines.FirstOrDefault(p => p.Name.ToUpper() == "ID" || p.AliasName == "ID");
                    }
                    if (key != null)
                    {
                        var orderbyname = string.IsNullOrEmpty(key.AliasName) ? key.Name : key.AliasName;

                        OrderBy(entity.TableName, orderbyname);

                        entity.OrderBy = GetForamtList(", ", "ORDER BY ", _sortList);
                    }
                    else
                    {
                        throw new Exception("Pagination requires the ORDER BY statement to be specified");
                    }
                }

                entity.PageNumber = pageNumber.Value;
            }
            return(_adapter.QueryPage(entity));
        }
Beispiel #2
0
        public string QueryPage(int pageSize, int?pageNumber = null)
        {
            SqlEntity entity = GetSqlEntity();

            entity.PageSize = pageSize;
            if (pageNumber.HasValue)
            {
                if (_sortList.Count == 0 && _adapter is SqlserverAdapter)
                {
                    throw new Exception("Pagination requires the ORDER BY statement to be specified");
                }
                entity.PageNumber = pageNumber.Value;
            }
            return(_adapter.QueryPage(entity));
        }