Exemplo n.º 1
0
        public static ExpressionTranslationResult TranslateLambda(LambdaExpression lambda, SimpleType[] parameterTypes, QueryAnalysisContext context)
        {
            if (parameterTypes.Length != lambda.Parameters.Count)
            {
                throw new Exception("The number of parameter types must match the number of parameters in the lambda.");
            }

            var newContext = new QueryAnalysisContext(context.TypeTranslationUtil, context.ParameterDictionary);

            //translatedParams are the new parameters that will be used in the lambda.
            var translatedParams = new List <ParameterExpression>();

            for (int i = 0; i < lambda.Parameters.Count; i++)
            {
                var newParam         = parameterTypes[i].GetParameter(lambda.Parameters[i].Name);
                var paramReplacement = new ParameterReplacement
                {
                    //replacementExpression will be a MemberExpression if the projection is modified.
                    //  since the original parameter has become Field0.
                    ReplacementExpression = parameterTypes[i].GetTranslatedParameterOrMember(newParam),
                    Type = parameterTypes[i].GetOriginalQueryableType()
                };
                newContext.ParameterDictionary.Add(lambda.Parameters[i], paramReplacement);

                translatedParams.Add(newParam);
            }

            var lambdaBody = new QueryTranslationVisitor(newContext).Translate(lambda.Body);
            var result     = Expression.Lambda(lambdaBody, translatedParams.ToArray());

            return(new ExpressionTranslationResult(result, newContext.QueryableType));
        }
Exemplo n.º 2
0
        public static ExpressionTranslationResult TranslateLambda(LambdaExpression lambda, SimpleType[] parameterTypes, QueryAnalysisContext context)
        {
            if (parameterTypes.Length != lambda.Parameters.Count)
                throw new Exception("The number of parameter types must match the number of parameters in the lambda.");

            var newContext = new QueryAnalysisContext(context.TypeTranslationUtil, context.ParameterDictionary);

            //translatedParams are the new parameters that will be used in the lambda.
            var translatedParams = new List<ParameterExpression>();

            for (int i = 0; i < lambda.Parameters.Count; i++)
            {
                var newParam = parameterTypes[i].GetParameter(lambda.Parameters[i].Name);
                var paramReplacement = new ParameterReplacement
                {
                    //replacementExpression will be a MemberExpression if the projection is modified.
                    //  since the original parameter has become Field0.
                    ReplacementExpression = parameterTypes[i].GetTranslatedParameterOrMember(newParam),
                    Type = parameterTypes[i].GetOriginalQueryableType()
                };
                newContext.ParameterDictionary.Add(lambda.Parameters[i], paramReplacement);

                translatedParams.Add(newParam);
            }

            var lambdaBody = new QueryTranslationVisitor(newContext).Translate(lambda.Body);
            var result = Expression.Lambda(lambdaBody, translatedParams.ToArray());

            return new ExpressionTranslationResult(result, newContext.QueryableType);
        }