private Expression CreateAggregationExpression(ParameterExpression accum, AggregateExpressionBase expression, Type baseType) { switch (expression.AggregateKind) { case AggregateExpressionKind.PropertyAggregate: return CreatePropertyAggregateExpression(accum, expression as AggregateExpression, baseType); case AggregateExpressionKind.EntitySetAggregate: return CreateEntitySetAggregateExpression(accum, expression as EntitySetAggregateExpression, baseType); default: throw new ODataException(Error.Format(SRResources.AggregateKindNotSupported, expression.AggregateKind)); } }
public void BindApplyWithCountInAggregateShouldReturnApplyClause() { IEnumerable <QueryToken> tokens = _parser.ParseApply("aggregate($count as TotalCount)"); ApplyBinder binder = new ApplyBinder(FakeBindMethods.BindSingleComplexProperty, _bindingState); ApplyClause actual = binder.BindApply(tokens); Assert.NotNull(actual); AggregateTransformationNode aggregate = Assert.IsType <AggregateTransformationNode>(Assert.Single(actual.Transformations)); Assert.Equal(TransformationNodeKind.Aggregate, aggregate.Kind); Assert.NotNull(aggregate.AggregateExpressions); AggregateExpressionBase statementBase = Assert.Single(aggregate.AggregateExpressions); AggregateExpression statement = Assert.IsType <AggregateExpression>(statementBase); Assert.Equal(AggregationMethod.VirtualPropertyCount, statement.Method); Assert.Equal("TotalCount", statement.Alias); }
private bool CompareAggregate(AggregateExpressionBase expression1, AggregateExpressionBase expression2) { if (expression1.AggregateKind != expression2.AggregateKind) { return(false); } if (expression1 is AggregateExpression aggregateExpression1 && expression2 is AggregateExpression aggregateExpression2) { return(CompareAggregate(aggregateExpression1, aggregateExpression2)); } if (expression1 is EntitySetAggregateExpression entitySetAggExpression1 && expression2 is EntitySetAggregateExpression entitySetAggExpression2) { return(CompareAggregate(entitySetAggExpression1, entitySetAggExpression2)); } throw new NotSupportedException("Unknown aggregate expression type " + expression1.GetType().Name); }