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; }
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(); }
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); }
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) });
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), });
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; }
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); } }