コード例 #1
0
 void AddSort()
 {
     if (Context.HasAnySort)
     {
         Expr = new SortExpressionCompiler <T>(Context.GuardNulls).Compile(Expr, Context.GetFullSort());
     }
 }
コード例 #2
0
        Expression BuildCore(Expression expr, bool paginate = false, bool isCountQuery = false, bool remoteGrouping = false)
        {
            var queryableType        = typeof(Queryable);
            var genericTypeArguments = new[] { typeof(T) };

            if (_context.HasFilter)
            {
                expr = Expression.Call(queryableType, "Where", genericTypeArguments, expr, Expression.Quote(new FilterExpressionCompiler <T>(_guardNulls, _context.UseStringToLower).Compile(_context.Filter)));
            }

            if (!isCountQuery)
            {
                if (!remoteGrouping)
                {
                    if (_context.HasAnySort)
                    {
                        expr = new SortExpressionCompiler <T>(_guardNulls).Compile(expr, _context.GetFullSort());
                    }
                    if (_context.HasAnySelect && _context.UseRemoteSelect)
                    {
                        expr = new SelectExpressionCompiler <T>(_guardNulls).Compile(expr, _context.FullSelect);
                        genericTypeArguments = expr.Type.GetGenericArguments();
                    }
                }
                else
                {
                    expr = new RemoteGroupExpressionCompiler <T>(_guardNulls, _anonTypeNewTweaks, _context.Group, _context.TotalSummary, _context.GroupSummary).Compile(expr);
                }

                if (paginate)
                {
                    if (_context.Skip > 0)
                    {
                        expr = Expression.Call(queryableType, "Skip", genericTypeArguments, expr, Expression.Constant(_context.Skip));
                    }

                    if (_context.Take > 0)
                    {
                        expr = Expression.Call(queryableType, "Take", genericTypeArguments, expr, Expression.Constant(_context.Take));
                    }
                }
            }

            if (isCountQuery)
            {
                expr = Expression.Call(queryableType, "Count", genericTypeArguments, expr);
            }

            return(expr);
        }
コード例 #3
0
        Expression BuildCore(Expression expr, bool paginate = false, bool isCountQuery = false, bool remoteGrouping = false, IList filterOverride = null, IReadOnlyList <string> selectOverride = null)
        {
            var queryableType        = typeof(Queryable);
            var genericTypeArguments = new[] { typeof(T) };

            if (filterOverride != null || _context.HasFilter)
            {
                var filterExpr = filterOverride != null && filterOverride.Count < 1
                    ? Expression.Lambda(Expression.Constant(false), Expression.Parameter(typeof(T)))
                    : new FilterExpressionCompiler <T>(_guardNulls, _context.UseStringToLower).Compile(filterOverride ?? _context.Filter);

                expr = Expression.Call(queryableType, "Where", genericTypeArguments, expr, Expression.Quote(filterExpr));
            }

            if (!isCountQuery)
            {
                if (!remoteGrouping)
                {
                    if (_context.HasAnySort)
                    {
                        expr = new SortExpressionCompiler <T>(_guardNulls).Compile(expr, _context.GetFullSort());
                    }
                    if (selectOverride != null || _context.HasAnySelect && _context.UseRemoteSelect)
                    {
                        expr = new SelectExpressionCompiler <T>(_guardNulls).Compile(expr, selectOverride ?? _context.FullSelect);
                        genericTypeArguments = expr.Type.GetGenericArguments();
                    }
                }
                else
                {
                    expr = new RemoteGroupExpressionCompiler <T>(_guardNulls, _anonTypeNewTweaks, _context.Group, _context.TotalSummary, _context.GroupSummary).Compile(expr);
                }

                if (paginate)
                {
                    if (_context.Skip > 0)
                    {
                        expr = Expression.Call(queryableType, "Skip", genericTypeArguments, expr, Expression.Constant(_context.Skip));
                    }

                    if (_context.Take > 0)
                    {
                        expr = Expression.Call(queryableType, "Take", genericTypeArguments, expr, Expression.Constant(_context.Take));
                    }
                }
            }

            if (isCountQuery)
            {
                expr = Expression.Call(queryableType, "Count", genericTypeArguments, expr);
            }

            return(expr);
        }