Example #1
0
        /// <summary>
        /// Generates the reversed order by.
        /// </summary>
        /// <returns></returns>
        public virtual string GenerateOrderByReversed()
        {
            StringBuilder sb = new StringBuilder();

            if (query.OrderBys.Count > 0)
            {
                sb.Append(SqlFragment.ORDER_BY);
                bool isFirst = true;
                foreach (OrderBySQ ob in query.OrderBys)
                {
                    if (!isFirst)
                    {
                        sb.Append(",");
                    }
                    sb.Append(OrderBySQ.GetOrderDirectionValue(OrderBySQ.ReverseDirection(ob.Direction)));
                    isFirst = false;
                }
                sb.AppendLine();
            }
            return(sb.ToString());
        }
Example #2
0
        /// <summary>
        /// Generates the 'order by' SQL clause.
        /// </summary>
        /// <param name="useReverseOrder">Generate the ORDER BY with sort order reversed for all columns/expressions.</param>
        /// <returns></returns>
        public virtual string GenerateOrderBy(bool useReverseOrder)
        {
            StringBuilder sb = new StringBuilder();

            if (query.OrderBys.Count > 0)
            {
                sb.Append(SqlFragment.ORDER_BY);
                bool isFirst = true;
                foreach (OrderBySQ o in query.OrderBys)
                {
                    if (!isFirst)
                    {
                        sb.Append(",");
                    }
                    sb.Append(o.ColumnNameOrExpression);
                    // SQL fragment starts with a space so don't add one
                    OrderBySQ.OrderDirection direction = useReverseOrder ? OrderBySQ.ReverseDirection(o.Direction) : o.Direction;
                    sb.Append(OrderBySQ.GetOrderDirectionValue((direction)));
                    isFirst = false;
                }
                sb.AppendLine();
            }
            return(sb.ToString());
        }