Beispiel #1
0
        public override Expression Visit(Expression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            if (!(expression is NewExpression ||
                  expression is MemberInitExpression ||
                  expression is EntityShaperExpression))
            {
                // This skips the group parameter from GroupJoin
                if (expression is ParameterExpression parameter &&
                    parameter.Type.IsGenericType &&
                    parameter.Type.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                {
                    return(parameter);
                }

                if (_clientEval)
                {
                    if (expression is ConstantExpression)
                    {
                        return(expression);
                    }

                    if (expression is ParameterExpression parameterExpression)
                    {
                        return(Expression.Call(
                                   _getParameterValueMethodInfo.MakeGenericMethod(parameterExpression.Type),
                                   QueryCompilationContext.QueryContextParameter,
                                   Expression.Constant(parameterExpression.Name)));
                    }

                    //if (expression is MethodCallExpression methodCallExpression
                    //    && methodCallExpression.Method.Name == "MaterializeCollectionNavigation")
                    //{
                    //    var result = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression.Arguments[0]);
                    //    var navigation = (INavigation)((ConstantExpression)methodCallExpression.Arguments[1]).Value;

                    //    return _selectExpression.AddCollectionProjection(result, navigation);
                    //}

                    var translation = _sqlTranslator.Translate(expression);
                    if (translation == null)
                    {
                        return(base.Visit(expression));
                    }
                    else
                    {
                        return(new ProjectionBindingExpression(
                                   _selectExpression, _selectExpression.AddToProjection(translation), expression.Type));
                    }
                }
                else
                {
                    var translation = _sqlTranslator.Translate(expression);
                    if (translation == null)
                    {
                        return(null);
                    }

                    _projectionMapping[_projectionMembers.Peek()] = translation;

                    return(new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), expression.Type));
                }
            }

            return(base.Visit(expression));
        }
        public override Expression Visit(Expression expression)
        {
            if (expression == null)
            {
                return(null);
            }

            if (expression is NewExpression ||
                expression is MemberInitExpression ||
                expression is EntityShaperExpression)
            {
                return(base.Visit(expression));
            }

            // This skips the group parameter from GroupJoin
            if (expression is ParameterExpression parameter &&
                parameter.Type.IsGenericType &&
                parameter.Type.GetGenericTypeDefinition() == typeof(IEnumerable <>))
            {
                return(parameter);
            }

            if (_clientEval)
            {
                switch (expression)
                {
                case ConstantExpression _:
                    return(expression);

                case ParameterExpression parameterExpression:
                    return(Expression.Call(
                               _getParameterValueMethodInfo.MakeGenericMethod(parameterExpression.Type),
                               QueryCompilationContext.QueryContextParameter,
                               Expression.Constant(parameterExpression.Name)));

                case MaterializeCollectionNavigationExpression materializeCollectionNavigationExpression:
                    return(base.Visit(expression));
                    //return _selectExpression.AddCollectionProjection(
                    //    _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(
                    //        materializeCollectionNavigationExpression.Subquery),
                    //    materializeCollectionNavigationExpression.Navigation, null);
                }

                var translation = _sqlTranslator.Translate(expression);
                if (translation == null)
                {
                    return(base.Visit(expression));
                }

                return(new ProjectionBindingExpression(
                           _selectExpression, _selectExpression.AddToProjection(translation), expression.Type));
            }
            else
            {
                var translation = _sqlTranslator.Translate(expression);
                if (translation == null)
                {
                    return(null);
                }

                _projectionMapping[_projectionMembers.Peek()] = translation;

                return(new ProjectionBindingExpression(_selectExpression, _projectionMembers.Peek(), expression.Type));
            }
        }