Esempio n. 1
0
        private TranslatedQuery PrepareSubqueryParameters(SubQueryExpression subQueryExpression, out Parameter <Tuple> parameterOfTuple, out Type elementType, out ProjectionExpression projection)
        {
            // 1. Rewrite recordset and ItemProjector to parameter<tuple>
            var subqueryTupleParameter = context.GetTupleParameter(subQueryExpression.OuterParameter);
            var newDataSource          = ApplyParameterToTupleParameterRewriter.Rewrite(
                subQueryExpression.ProjectionExpression.ItemProjector.DataSource,
                subqueryTupleParameter,
                subQueryExpression.ApplyParameter);

            var newItemProjectorBody = ApplyParameterToTupleParameterRewriter.Rewrite(
                subQueryExpression.ProjectionExpression.ItemProjector.Item,
                subqueryTupleParameter,
                subQueryExpression.ApplyParameter);

            var itemProjector = new ItemProjectorExpression(newItemProjectorBody, newDataSource, subQueryExpression.ProjectionExpression.ItemProjector.Context);

            parameterOfTuple = context.GetTupleParameter(subQueryExpression.OuterParameter);

            // 2. Add only parameter<tuple>. Tuple value will be assigned
            // at the moment of materialization in SubQuery constructor
            projection = new ProjectionExpression(
                subQueryExpression.ProjectionExpression.Type,
                itemProjector,
                subQueryExpression.ProjectionExpression.TupleParameterBindings,
                subQueryExpression.ProjectionExpression.ResultType);

            // 3. Make translation
            elementType = subQueryExpression.ProjectionExpression.ItemProjector.Item.Type;
            var resultType      = SequenceHelper.GetSequenceType(elementType);
            var translateMethod = Translator.TranslateMethod.MakeGenericMethod(new[] { resultType });

            return((TranslatedQuery)translateMethod.Invoke(context.Translator, new object[] { projection, tupleParameters.AddOne(parameterOfTuple) }));
        }