コード例 #1
0
        public static void Render <T>(IEnumerable <ResultOrderingModel> orderBy, StringBuilder sb)
        {
            var olist = orderBy?.ToList();

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

            sb.Append(" ORDER BY ");

            for (var i = 0; i < olist.Count; i++)
            {
                if (i > 0)
                {
                    sb.Append(", ");
                }

                var order = olist[i];

                var propchain = ExpressionsHelper.GetPropertiesChainText <T>(ExpressionsHelper.RemoveConvert(order.Expression));
                if (string.IsNullOrWhiteSpace(propchain))
                {
                    throw new InvalidOperationException($"Invalid OrderBy expression {order.Expression}");
                }

                var tabAndCol = DotPathHelper.SplitToEntityAndAttribute(propchain);

                sb.Append($"[{tabAndCol.Item1}].[{tabAndCol.Item2}]");

                sb.Append(order.Ascending ? " ASC" : " DESC");
            }

            sb.AppendLine();
        }
コード例 #2
0
        protected override IQuerySegment MapMemberExpression(MemberExpression expression)
        {
            var propChain = ExpressionsHelper.GetPropertiesChainText <T>(expression);

            if (string.IsNullOrWhiteSpace(propChain))
            {
                throw new NotSupportedException($"Unsupported expression {expression}");
            }

            var tableAndColumn = DotPathHelper.SplitToEntityAndAttribute(propChain);

            var tableAlias = tableAndColumn.Item1;
            var column     = tableAndColumn.Item2;

            return(new ColumnSegment(tableAlias, column));
        }