Beispiel #1
0
        private IEdmTypeReference CreateAggregateStatementTypeReference(SingleValueNode expression, AggregationVerb withVerb)
        {
            var expressionType = expression.TypeReference;

            if (expressionType == null && aggregateStatementsCache != null)
            {
                var openProperty = expression as SingleValueOpenPropertyAccessNode;
                if (openProperty != null)
                {
                    expressionType = GetTypeReferenceByPropertyName(openProperty.Name);
                }
            }

            switch (withVerb)
            {
            case AggregationVerb.Average:
                var expressionPrimitiveKind = expressionType.PrimitiveKind();
                switch (expressionPrimitiveKind)
                {
                case EdmPrimitiveTypeKind.Int32:
                case EdmPrimitiveTypeKind.Int64:
                case EdmPrimitiveTypeKind.Double:
                    return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Double, expressionType.IsNullable));

                case EdmPrimitiveTypeKind.Decimal:
                    return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Decimal, expressionType.IsNullable));

                default:
                    throw new ODataException(
                              ODataErrorStrings.ApplyBinder_AggregateStatementIncompatibleTypeForVerb(expression,
                                                                                                      expressionPrimitiveKind));
                }

            case AggregationVerb.CountDistinct:
                return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int64, false));

            case AggregationVerb.Max:
            case AggregationVerb.Min:
            case AggregationVerb.Sum:
                return(expressionType);

            default:
                throw new ODataException(ODataErrorStrings.ApplyBinder_UnsupportedAggregateVerb(withVerb));
            }
        }