protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
        {
            var method = expression.Method.IsGenericMethod
                                                         ? expression.Method.GetGenericMethodDefinition()
                                                         : expression.Method;

            if (_pagingMethods.Contains(method) && !_sessionFactory.Dialect.SupportsVariableLimit)
            {
                //TODO: find a way to make this code cleaner
                var query = VisitExpression(expression.Arguments[0]);
                var arg   = expression.Arguments[1];

                if (query == expression.Arguments[0])
                {
                    return(expression);
                }

                return(Expression.Call(null, expression.Method, query, arg));
            }

            if (VisitorUtil.IsDynamicComponentDictionaryGetter(expression, _sessionFactory))
            {
                return(expression);
            }

            return(base.VisitMethodCallExpression(expression));
        }
 protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
 {
     if (VisitorUtil.IsDynamicComponentDictionaryGetter(expression, _sessionFactory))
     {
         return(expression);
     }
     return(base.VisitMethodCallExpression(expression));
 }
Esempio n. 3
0
        protected override Expression VisitMethodCall(MethodCallExpression expression)
        {
            if (VisitorUtil.IsMappedAs(expression.Method))
            {
                var rawParameter = Visit(expression.Arguments[0]);
                // TODO 6.0: Remove below code and return expression as this logic is now inside ConstantTypeLocator
                var parameter = ParameterTypeLocator.UnwrapUnary(rawParameter) as ConstantExpression;
                var type      = expression.Arguments[1] as ConstantExpression;
                if (parameter == null)
                {
                    throw new HibernateException(
                              $"{nameof(LinqExtensionMethods.MappedAs)} must be called on an expression which can be evaluated as " +
                              $"{nameof(ConstantExpression)}. It was call on {rawParameter?.GetType().Name ?? "null"} instead.");
                }
                if (type == null)
                {
                    throw new HibernateException(
                              $"{nameof(LinqExtensionMethods.MappedAs)} type must be supplied as {nameof(ConstantExpression)}. " +
                              $"It was {expression.Arguments[1]?.GetType().Name ?? "null"} instead.");
                }

                _parameters[parameter].Type = (IType)type.Value;

                return(rawParameter);
            }

            var method = expression.Method.IsGenericMethod
                                                         ? expression.Method.GetGenericMethodDefinition()
                                                         : expression.Method;

            if (PagingMethods.Contains(method) && !_sessionFactory.Dialect.SupportsVariableLimit)
            {
                var query = Visit(expression.Arguments[0]);
                //TODO 6.0: Remove the below code and return expression
                var arg = expression.Arguments[1];

                if (query == expression.Arguments[0])
                {
                    return(expression);
                }

                return(Expression.Call(null, expression.Method, query, arg));
            }

            if (_functionRegistry != null &&
                _functionRegistry.TryGetGenerator(method, out var generator) &&
                generator.TryGetCollectionParameters(expression, out var collectionParameter))
            {
                _collectionParameters.Add(collectionParameter);
            }

            if (VisitorUtil.IsDynamicComponentDictionaryGetter(expression, _sessionFactory))
            {
                return(expression);
            }

            return(base.VisitMethodCall(expression));
        }
        protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
        {
            if (expression.Method.Name == nameof(LinqExtensionMethods.MappedAs) && expression.Method.DeclaringType == typeof(LinqExtensionMethods))
            {
                var rawParameter = VisitExpression(expression.Arguments[0]);
                var parameter    = rawParameter as ConstantExpression;
                var type         = expression.Arguments[1] as ConstantExpression;
                if (parameter == null)
                {
                    throw new HibernateException(
                              $"{nameof(LinqExtensionMethods.MappedAs)} must be called on an expression which can be evaluated as " +
                              $"{nameof(ConstantExpression)}. It was call on {rawParameter?.GetType().Name ?? "null"} instead.");
                }
                if (type == null)
                {
                    throw new HibernateException(
                              $"{nameof(LinqExtensionMethods.MappedAs)} type must be supplied as {nameof(ConstantExpression)}. " +
                              $"It was {expression.Arguments[1]?.GetType().Name ?? "null"} instead.");
                }

                _parameters[parameter].Type = (IType)type.Value;

                return(parameter);
            }

            var method = expression.Method.IsGenericMethod
                                                         ? expression.Method.GetGenericMethodDefinition()
                                                         : expression.Method;

            if (_pagingMethods.Contains(method) && !_sessionFactory.Dialect.SupportsVariableLimit)
            {
                //TODO: find a way to make this code cleaner
                var query = VisitExpression(expression.Arguments[0]);
                var arg   = expression.Arguments[1];

                if (query == expression.Arguments[0])
                {
                    return(expression);
                }

                return(Expression.Call(null, expression.Method, query, arg));
            }

            if (VisitorUtil.IsDynamicComponentDictionaryGetter(expression, _sessionFactory))
            {
                return(expression);
            }

            return(base.VisitMethodCallExpression(expression));
        }
Esempio n. 5
0
        protected override Expression VisitMethodCallExpression(MethodCallExpression expression)
        {
            if (expression.Method.Name == "MappedAs" && expression.Method.DeclaringType == typeof(LinqExtensionMethods))
            {
                var parameter = (ConstantExpression)VisitExpression(expression.Arguments[0]);
                var type      = (ConstantExpression)expression.Arguments[1];

                _parameters[parameter].Type = (IType)type.Value;

                return(parameter);
            }

            var method = expression.Method.IsGenericMethod
                                                         ? expression.Method.GetGenericMethodDefinition()
                                                         : expression.Method;

            if (_pagingMethods.Contains(method) && !_sessionFactory.Dialect.SupportsVariableLimit)
            {
                //TODO: find a way to make this code cleaner
                var query = VisitExpression(expression.Arguments[0]);
                var arg   = expression.Arguments[1];

                if (query == expression.Arguments[0])
                {
                    return(expression);
                }

                return(Expression.Call(null, expression.Method, query, arg));
            }

            if (VisitorUtil.IsDynamicComponentDictionaryGetter(expression, _sessionFactory))
            {
                return(expression);
            }

            return(base.VisitMethodCallExpression(expression));
        }