System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.CreateCanonicalFunction C# (CSharp) Method

CreateCanonicalFunction() private method

Creates a canonical function with the given name and the given arguments
private CreateCanonicalFunction ( string functionName, Expression Expression ) : DbFunctionExpression
functionName string Should represent a non-aggregate canonical function
Expression System.Linq.Expressions.Expression Passed only for error handling purposes
return DbFunctionExpression
        private DbFunctionExpression CreateCanonicalFunction(
            string functionName, Expression Expression, params DbExpression[] translatedArguments)
        {
            var translatedArgumentTypes = new List<TypeUsage>(translatedArguments.Length);
            foreach (var translatedArgument in translatedArguments)
            {
                translatedArgumentTypes.Add(translatedArgument.ResultType);
            }
            var function = FindCanonicalFunction(functionName, translatedArgumentTypes, false /* isGroupAggregateFunction */, Expression);
            return function.Invoke(translatedArguments);
        }

Usage Example

コード例 #1
0
            internal static CqtExpression ConcatArgs(ExpressionConverter parent, Expression linq, Expression[] linqArgs)
            {
                var args = linqArgs
                        .Where(arg => !arg.IsNullConstant()) // remove null constants   
                        .Select(arg => ConvertToString(parent, arg)) // Apply ToString semantics                    
                        .ToArray();

                //if all args was null constants, optimize the entire expression to constant "" 
                // e.g null + null + null == ""
                if (args.Length == 0)
                {
                    return DbExpressionBuilder.Constant(string.Empty);
                }

                var current = args.First();
                foreach (var next in args.Skip(1)) //concat all args
                {
                    current = parent.CreateCanonicalFunction(Concat, linq, current, next);
                }

                return current;
            }