Exemplo n.º 1
0
        public AggregateExpression(Type type, Expression expression, AggregateSqlFunction aggregateFunction)
            : base(DbExpressionType.Aggregate, type)
        {
            if (expression == null && aggregateFunction != AggregateSqlFunction.Count)
            {
                throw new ArgumentNullException("expression");
            }

            this.Expression        = expression;
            this.AggregateFunction = aggregateFunction;
        }
Exemplo n.º 2
0
        public AggregateExpression(Type type, AggregateSqlFunction aggregateFunction, IEnumerable <Expression> arguments)
            : base(DbExpressionType.Aggregate, type)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            this.AggregateFunction = aggregateFunction;
            this.Arguments         = arguments.ToReadOnly();
        }
Exemplo n.º 3
0
        private Expression BindAggregate(Type resultType, AggregateSqlFunction aggregateFunction, Expression source, LambdaExpression selector)
        {
            MetaProjectorExpression mp = AsProjection(Visit(source));

            if (selector == null)
            {
                return(mp.Projector);
            }

            Expression projector = MapAndVisit(selector, mp);

            return(projector);
        }
Exemplo n.º 4
0
 string GetAggregateFunction(AggregateSqlFunction agg)
 {
     return(agg switch
     {
         AggregateSqlFunction.Average => "AVG",
         AggregateSqlFunction.StdDev => !isPostgres ? "STDEV" : "stddev_samp",
         AggregateSqlFunction.StdDevP => !isPostgres? "STDEVP" : "stddev_pop",
         AggregateSqlFunction.Count => "COUNT",
         AggregateSqlFunction.CountDistinct => "COUNT",
         AggregateSqlFunction.Max => "MAX",
         AggregateSqlFunction.Min => "MIN",
         AggregateSqlFunction.Sum => "SUM",
         AggregateSqlFunction.string_agg => "string_agg",
         _ => throw new UnexpectedValueException(agg)
     });
Exemplo n.º 5
0
    public static bool OrderMatters(this AggregateSqlFunction aggregateFunction)
    {
        return(aggregateFunction switch
        {
            AggregateSqlFunction.Average or
            AggregateSqlFunction.StdDev or
            AggregateSqlFunction.StdDevP or
            AggregateSqlFunction.Count or
            AggregateSqlFunction.CountDistinct or
            AggregateSqlFunction.Min or
            AggregateSqlFunction.Max or
            AggregateSqlFunction.Sum => false,

            AggregateSqlFunction.string_agg => true,
            _ => throw new UnexpectedValueException(aggregateFunction),
        });
Exemplo n.º 6
0
        public AggregateExpression(Type type, Expression expression, AggregateSqlFunction aggregateFunction, bool distinct)
            : base(DbExpressionType.Aggregate, type)
        {
            if (aggregateFunction != AggregateSqlFunction.Count && expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            if (distinct && (aggregateFunction != AggregateSqlFunction.Count || expression == null))
            {
                throw new ArgumentException("Distinct only allowed for Count with expression");
            }

            this.Distinct          = distinct;
            this.Expression        = expression;
            this.AggregateFunction = aggregateFunction;
        }
Exemplo n.º 7
0
        public static bool OrderMatters(this AggregateSqlFunction aggregateFunction)
        {
            switch (aggregateFunction)
            {
            case AggregateSqlFunction.Average:
            case AggregateSqlFunction.StdDev:
            case AggregateSqlFunction.StdDevP:
            case AggregateSqlFunction.Count:
            case AggregateSqlFunction.CountDistinct:
            case AggregateSqlFunction.Min:
            case AggregateSqlFunction.Max:
            case AggregateSqlFunction.Sum:
                return(false);

            case AggregateSqlFunction.string_agg:
                return(true);

            default:
                throw new UnexpectedValueException(aggregateFunction);
            }
        }