예제 #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));
        }
예제 #2
0
        public static ExpressionTranslationResult VisitWithNewVisitor(Expression expression, QueryAnalysisContext outerContext, bool modifyProjection)
        {
            var newContext = new QueryAnalysisContext(outerContext.TypeTranslationUtil)
            {
                ModifyProjection = modifyProjection
            };

            foreach (var kvp in outerContext.ParameterDictionary)
            {
                newContext.ParameterDictionary.Add(kvp.Key, kvp.Value);
            }
            var result = new QueryTranslationVisitor(newContext).Translate(expression);

            return(new ExpressionTranslationResult(result, newContext.QueryableType));
        }
예제 #3
0
 public static ExpressionTranslationResult VisitWithNewVisitor(Expression expression, QueryAnalysisContext outerContext, bool modifyProjection)
 {
     var newContext = new QueryAnalysisContext(outerContext.TypeTranslationUtil) { ModifyProjection = modifyProjection };
     foreach (var kvp in outerContext.ParameterDictionary) newContext.ParameterDictionary.Add(kvp.Key, kvp.Value);
     var result = new QueryTranslationVisitor(newContext).Translate(expression);
     return new ExpressionTranslationResult(result, newContext.QueryableType);
 }
예제 #4
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);
        }