示例#1
0
 private static void Validate(QueryexBase exp)
 {
     // Cannot contain aggregations
     if (exp.ContainsAggregations)
     {
         throw new InvalidOperationException("Filter expression cannot contain aggregation functions like Sum or Count.");
     }
 }
示例#2
0
        private static void Validate(QueryexBase exp)
        {                // This is a measure, every column access must be surrounded by an aggregation function
            var exposedColumnAccess = exp.UnaggregatedColumnAccesses().FirstOrDefault();

            if (exposedColumnAccess != null)
            {
                throw new QueryException($"Having parameter contains a column access {exposedColumnAccess} that is not contained within an aggregation.");
            }
        }
示例#3
0
        public void ParsesToCorrectType(string input, Type expected)
        {
            // Act
            var asts = QueryexBase.Parse(input);

            // Assert
            var actual = Assert.Single(asts);

            Assert.IsType(expected, actual);
        }
示例#4
0
        /// <summary>
        /// Parses a string representing an expand argument into an <see cref="ExpressionExpand"/>.
        /// The expand argument is a comma separated list of column accesses.
        /// For example "Participant,Lines.Entries"
        /// </summary>
        public static ExpressionExpand Parse(string expand)
        {
            if (string.IsNullOrWhiteSpace(expand))
            {
                return(null);
            }

            var expressions     = QueryexBase.Parse(expand, expectPathsOnly: true);
            var nonColumnAccess = expressions.FirstOrDefault(e => !(e is QueryexColumnAccess));

            if (nonColumnAccess != null)
            {
                throw new QueryException($"Expand parameter cannot contain an expression like {nonColumnAccess}, only column access expressions are allowed.");
            }

            return(new ExpressionExpand(expressions.Cast <QueryexColumnAccess>()));
        }
示例#5
0
        /// <summary>
        /// Parses a string representing a select argument into an <see cref="ExpressionSelect"/>.
        /// The select argument is a comma separated list of column accesses.
        /// For example: "Line.PostingDate,Value"
        /// </summary>
        public static ExpressionSelect Parse(string select)
        {
            if (string.IsNullOrWhiteSpace(select))
            {
                return(null);
            }

            var expressions     = QueryexBase.Parse(select);
            var nonColumnAccess = expressions.FirstOrDefault(e => e is not QueryexColumnAccess);

            if (nonColumnAccess != null)
            {
                throw new QueryException($"Select parameter cannot contain an expression like {nonColumnAccess}, only column access expressions are allowed.");
            }

            return(new ExpressionSelect(expressions.Cast <QueryexColumnAccess>()));
        }
示例#6
0
        /// <summary>
        /// Parses a string representing a filter argument into a <see cref="ExpressionFilter"/>. 
        /// The syntax is anything that can be compiled by <see cref="QueryexBase"/> into a single boolean expression.
        /// For example: "(Value * Direction > 1000) and (Agent.Lookup1.Code = 'M')".
        /// </summary>
        public static ExpressionFilter Parse(string filter)
        {
            var expressions = QueryexBase.Parse(filter);

            // Can only contain 0 or 1 atoms
            if (expressions.Skip(1).Any())
            {
                throw new InvalidOperationException("Filter parameter must contain a single expression without top level commas.");
            }

            var filterExpression = expressions.FirstOrDefault();
            if (filterExpression == null)
            {
                return null;
            }

            return new ExpressionFilter(filterExpression);
        }
示例#7
0
        /// <summary>
        /// Parses a string representing a filter argument into a <see cref="ExpressionHaving"/>.
        /// The filter argument is a boolean expression. The syntax is anything that can be compiled by
        /// <see cref="QueryexBase"/> into a single boolean expression where every column access is contained within an aggregation.
        /// For example: "SUM(Value * Direction) > 1000 and Max(Participant.Lookup1.Code) = 'M'".
        /// </summary>
        public static ExpressionHaving Parse(string having)
        {
            var expressions = QueryexBase.Parse(having);

            // Can only contain 0 or 1 atoms
            if (expressions.Skip(1).Any())
            {
                throw new InvalidOperationException("Having parameter must contain a single expression without top level commas.");
            }

            var havingExpression = expressions.FirstOrDefault();

            if (havingExpression == null)
            {
                return(null);
            }

            return(new ExpressionHaving(havingExpression));
        }
示例#8
0
 static bool IsId(QueryexBase ex)
 {
     return(ex is QueryexColumnAccess ca && ca.Path.Length == 0 && ca.Property == "Id");
 }
示例#9
0
        public ExpressionHaving(QueryexBase expression)
        {
            Expression = expression;

            Validate(Expression);
        }
示例#10
0
 public SqlDynamicColumn(QueryexBase exp, int targetIndex)
 {
     Expression  = exp;
     TargetIndex = targetIndex;
 }
示例#11
0
        public ExpressionFilter(QueryexBase expression)
        {
            Expression = expression;

            Validate(Expression);
        }