예제 #1
0
        public string OrderBy(IEnumerable <DynamicQueryOrder> orders, bool fieldConverter = true)
        {
            if (orders == null || !orders.Any())
            {
                return(string.Empty);
            }

            return(string.Join(",", orders.Select(item =>
            {
                var name = item.Name;

                if (fieldConverter)
                {
                    name = CharacterConverter.FieldConverter(item.Name);
                }

                if (SqlFieldMappings.Any(x => x.Key == name))
                {
                    name = SqlFieldMappings.First(x => x.Key == name).SqlField;
                }

                var order = item.Sort == ListSortDirection.Ascending
                  ? "ASC"
                  : "DESC";

                return $" {name} {order} ";
            })));
        }