Exemplo n.º 1
0
        private Expression GetTupleExpression(ParameterizedExpression expression)
        {
            if (expression.OuterParameter == null)
            {
                return(tupleParameter);
            }

            var parameterOfTuple = context.GetTupleParameter(expression.OuterParameter);

            if (tupleParameters.Contains(parameterOfTuple))
            {
                // Make access on Parameter<Tuple>
                return(Expression.MakeMemberAccess(Expression.Constant(parameterOfTuple), WellKnownMembers.ParameterOfTupleValue));
            }

            // Use ApplyParameter for RecordSet predicates
            if (itemMaterializationContextParameter == null)
            {
                var projectionExpression     = context.Bindings[expression.OuterParameter];
                var applyParameter           = context.GetApplyParameter(projectionExpression);
                var applyParameterExpression = Expression.Constant(applyParameter);
                return(Expression.Property(applyParameterExpression, WellKnownMembers.ApplyParameterValue));
            }

            return(tupleParameter);
        }
        // Constructors

        public ItemProjectorExpression(Expression expression, CompilableProvider dataSource, TranslatorContext context)
            : base(ExtendedExpressionType.ItemProjector, expression.Type)
        {
            DataSource = dataSource;
            Context    = context;
            var newApplyParameter      = Context.GetApplyParameter(dataSource);
            var applyParameterReplacer = new ExtendedExpressionReplacer(ex =>
                                                                        ex is SubQueryExpression
          ? ((SubQueryExpression)ex).ReplaceApplyParameter(newApplyParameter)
          : null);

            Item = applyParameterReplacer.Replace(expression);
        }