private IEdmTypeReference CreateAggregateExpressionTypeReference(SingleValueNode expression, AggregationMethod withVerb) { var expressionType = expression.TypeReference; if (expressionType == null && aggregateExpressionsCache != null) { var openProperty = expression as SingleValueOpenPropertyAccessNode; if (openProperty != null) { expressionType = GetTypeReferenceByPropertyName(openProperty.Name); } } switch (withVerb) { case AggregationMethod.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_AggregateExpressionIncompatibleTypeForMethod(expression, expressionPrimitiveKind)); } case AggregationMethod.CountDistinct: return(EdmCoreModel.Instance.GetPrimitive(EdmPrimitiveTypeKind.Int64, false)); case AggregationMethod.Max: case AggregationMethod.Min: case AggregationMethod.Sum: return(expressionType); default: throw new ODataException(ODataErrorStrings.ApplyBinder_UnsupportedAggregateMethod(withVerb)); } }