/// <summary>
        /// Reports function overload resolution error.
        /// </summary>
        internal static void ReportFunctionOverloadError(AST.MethodExpr functionExpr, EdmFunction functionType, List <TypeUsage> argTypes)
        {
            string strDelim = "";

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(functionType.Name).Append("(");
            for (int i = 0; i < argTypes.Count; i++)
            {
                sb.Append(strDelim);
                sb.Append(argTypes[i] != null ? argTypes[i].EdmType.FullName : "NULL");
                strDelim = ", ";
            }
            sb.Append(")");

            Func <object, object, object, string> formatString;

            if (TypeSemantics.IsAggregateFunction(functionType))
            {
                formatString = TypeHelpers.IsCanonicalFunction(functionType) ?
                               (Func <object, object, object, string>)System.Data.Entity.Strings.NoCanonicalAggrFunctionOverloadMatch :
                               (Func <object, object, object, string>)System.Data.Entity.Strings.NoAggrFunctionOverloadMatch;
            }
            else
            {
                formatString = TypeHelpers.IsCanonicalFunction(functionType) ?
                               (Func <object, object, object, string>)System.Data.Entity.Strings.NoCanonicalFunctionOverloadMatch :
                               (Func <object, object, object, string>)System.Data.Entity.Strings.NoFunctionOverloadMatch;
            }

            throw EntityUtil.EntitySqlError(functionExpr.ErrCtx.CommandText,
                                            formatString(functionType.NamespaceName, functionType.Name, sb.ToString()),
                                            functionExpr.ErrCtx.InputPosition,
                                            System.Data.Entity.Strings.CtxFunction(functionType.Name),
                                            false /* loadContextInfoFromResource */);
        }
Example #2
0
 internal static bool IsCollectionAggregateFunction(FunctionOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     if (n.Children.Count == 1 && TypeSemantics.IsCollectionType(n.Child0.Op.Type))
     {
         return(TypeSemantics.IsAggregateFunction(op.Function));
     }
     return(false);
 }
Example #3
0
        internal static void ReportFunctionOverloadError(
            MethodExpr functionExpr,
            EdmFunction functionType,
            List <TypeUsage> argTypes)
        {
            string        str           = "";
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append(functionType.Name).Append("(");
            for (int index = 0; index < argTypes.Count; ++index)
            {
                stringBuilder.Append(str);
                stringBuilder.Append(argTypes[index] != null ? argTypes[index].EdmType.FullName : "NULL");
                str = ", ";
            }
            stringBuilder.Append(")");
            Func <object, object, object, string> func = !TypeSemantics.IsAggregateFunction(functionType) ? (TypeHelpers.IsCanonicalFunction(functionType) ? new Func <object, object, object, string>(Strings.NoCanonicalFunctionOverloadMatch) : new Func <object, object, object, string>(Strings.NoFunctionOverloadMatch)) : (TypeHelpers.IsCanonicalFunction(functionType) ? new Func <object, object, object, string>(Strings.NoCanonicalAggrFunctionOverloadMatch) : new Func <object, object, object, string>(Strings.NoAggrFunctionOverloadMatch));

            throw EntitySqlException.Create(functionExpr.ErrCtx.CommandText, func((object)functionType.NamespaceName, (object)functionType.Name, (object)stringBuilder.ToString()), functionExpr.ErrCtx.InputPosition, Strings.CtxFunction((object)functionType.Name), false, (Exception)null);
        }
Example #4
0
 internal static DbExpressionList ValidateFunctionAggregate(
     EdmFunction function,
     IEnumerable <DbExpression> args)
 {
     ArgumentValidation.CheckFunction(function);
     if (!TypeSemantics.IsAggregateFunction(function) || function.ReturnParameter == null)
     {
         throw new ArgumentException(Strings.Cqt_Aggregate_InvalidFunction, nameof(function));
     }
     FunctionParameter[] expectedParams = ArgumentValidation.GetExpectedParameters(function);
     return(ArgumentValidation.CreateExpressionList(args, "argument", expectedParams.Length, (Action <DbExpression, int>)((exp, idx) =>
     {
         TypeUsage typeUsage = expectedParams[idx].TypeUsage;
         TypeUsage elementType = (TypeUsage)null;
         if (TypeHelpers.TryGetCollectionElementType(typeUsage, out elementType))
         {
             typeUsage = elementType;
         }
         ArgumentValidation.RequireCompatibleType(exp, typeUsage, "argument");
     })));
 }
Example #5
0
        // <summary>
        // Reports function overload resolution error.
        // </summary>
        internal static void ReportFunctionOverloadError(MethodExpr functionExpr, EdmFunction functionType, List <TypeUsage> argTypes)
        {
            var strDelim = "";
            var sb       = new StringBuilder();

            sb.Append(functionType.Name).Append("(");
            for (var i = 0; i < argTypes.Count; i++)
            {
                sb.Append(strDelim);
                sb.Append(argTypes[i] != null ? argTypes[i].EdmType.FullName : "NULL");
                strDelim = ", ";
            }
            sb.Append(")");

            Func <object, object, object, string> formatString;

            if (TypeSemantics.IsAggregateFunction(functionType))
            {
                formatString = TypeHelpers.IsCanonicalFunction(functionType)
                                   ? Strings.NoCanonicalAggrFunctionOverloadMatch
                                   : (Func <object, object, object, string>)Strings.NoAggrFunctionOverloadMatch;
            }
            else
            {
                formatString = TypeHelpers.IsCanonicalFunction(functionType)
                                   ? Strings.NoCanonicalFunctionOverloadMatch
                                   : (Func <object, object, object, string>)Strings.NoFunctionOverloadMatch;
            }

            throw EntitySqlException.Create(
                      functionExpr.ErrCtx.CommandText,
                      formatString(functionType.NamespaceName, functionType.Name, sb.ToString()),
                      functionExpr.ErrCtx.InputPosition,
                      Strings.CtxFunction(functionType.Name),
                      false,
                      null);
        }
Example #6
0
 /// <summary>
 ///     Is this function a collection aggregate function. It is, if
 ///     - it has exactly one child
 ///     - that child is a collection type
 ///     - and the function has been marked with the aggregate attribute
 /// </summary>
 /// <param name="op"> the function op </param>
 /// <param name="n"> the current subtree </param>
 /// <returns> true, if this was a collection aggregate function </returns>
 internal static bool IsCollectionAggregateFunction(FunctionOp op, Node n)
 {
     return((n.Children.Count == 1) &&
            TypeSemantics.IsCollectionType(n.Child0.Op.Type) &&
            TypeSemantics.IsAggregateFunction(op.Function));
 }