コード例 #1
0
        /// <summary>
        /// Returns an expression suitable for usage with LINQ Dynamic
        /// that represents the default sort ordering of instances of the class.
        /// </summary>
        public string DefaultOrderByClause(string prependText = "")
        {
            var defaultOrderBy = DefaultOrderBy.ToList();

            if (defaultOrderBy.Count == 0)
            {
                return(null);
            }

            var orderByClauseList = new List <string>();

            foreach (var orderInfo in defaultOrderBy)
            {
                if (orderInfo.OrderByDirection == DefaultOrderByAttribute.OrderByDirections.Ascending)
                {
                    orderByClauseList.Add($"{orderInfo.OrderExpression(prependText)} ASC");
                }
                else
                {
                    orderByClauseList.Add($"{orderInfo.OrderExpression(prependText)} DESC");
                }
            }

            return(string.Join(",", orderByClauseList));
        }
コード例 #2
0
        public string DefaultOrderByClause(string prependText = "")
        {
            var defaultOrderBy = DefaultOrderBy.ToList();

            if (defaultOrderBy.Any())
            {
                var orderByClauseList = new List <string>();
                foreach (var orderInfo in defaultOrderBy)
                {
                    if (orderInfo.OrderByDirection == DefaultOrderByAttribute.OrderByDirections.Ascending)
                    {
                        orderByClauseList.Add($"{prependText}{orderInfo.FieldName} ASC");
                    }
                    else
                    {
                        orderByClauseList.Add($"{prependText}{orderInfo.FieldName} DESC");
                    }
                }
                return(string.Join(",", orderByClauseList));
            }
            return(null);
        }