コード例 #1
0
        public virtual (SelectExpression selectExpression, bool canCache) Optimize(
            [NotNull] SelectExpression selectExpression,
            [NotNull] IReadOnlyDictionary <string, object> parametersValues)
        {
            Check.NotNull(selectExpression, nameof(selectExpression));
            Check.NotNull(parametersValues, nameof(parametersValues));

            var canCache = true;

            var inExpressionOptimized = new InExpressionValuesExpandingExpressionVisitor(
                Dependencies.SqlExpressionFactory, parametersValues).Visit(selectExpression);

            if (!ReferenceEquals(selectExpression, inExpressionOptimized))
            {
                canCache = false;
            }

            var nullParametersOptimized = new ParameterNullabilityBasedSqlExpressionOptimizingExpressionVisitor(
                Dependencies.SqlExpressionFactory, UseRelationalNulls, parametersValues).Visit(inExpressionOptimized);

            var fromSqlParameterOptimized = new FromSqlParameterApplyingExpressionVisitor(
                Dependencies.SqlExpressionFactory,
                Dependencies.ParameterNameGeneratorFactory.Create(),
                parametersValues).Visit(nullParametersOptimized);

            if (!ReferenceEquals(nullParametersOptimized, fromSqlParameterOptimized))
            {
                canCache = false;
            }

            return(selectExpression : (SelectExpression)fromSqlParameterOptimized, canCache);
        }
コード例 #2
0
            public (SelectExpression selectExpression, bool canCache) Optimize(SelectExpression selectExpression, IReadOnlyDictionary <string, object> parametersValues)
            {
                var canCache = true;

                var inExpressionOptimized = new InExpressionValuesExpandingExpressionVisitor(
                    _sqlExpressionFactory, parametersValues).Visit(selectExpression);

                if (!ReferenceEquals(selectExpression, inExpressionOptimized))
                {
                    canCache = false;
                }

                var nullParametersOptimized = new ParameterNullabilityBasedSqlExpressionOptimizingExpressionVisitor(
                    _sqlExpressionFactory, _useRelationalNulls, parametersValues).Visit(inExpressionOptimized);

                var fromSqlParameterOptimized = new FromSqlParameterApplyingExpressionVisitor(
                    _sqlExpressionFactory,
                    _parameterNameGeneratorFactory.Create(),
                    parametersValues).Visit(nullParametersOptimized);

                if (!ReferenceEquals(nullParametersOptimized, fromSqlParameterOptimized))
                {
                    canCache = false;
                }

                return(selectExpression : (SelectExpression)fromSqlParameterOptimized, canCache);
            }
        public virtual (SelectExpression, bool) Optimize(
            [NotNull] SelectExpression selectExpression,
            [NotNull] IReadOnlyDictionary <string, object> parametersValues)
        {
            Check.NotNull(selectExpression, nameof(selectExpression));
            Check.NotNull(parametersValues, nameof(parametersValues));

            var canCache = true;

            var(sqlExpressionOptimized, optimizerCanCache) = new NullabilityBasedSqlProcessingExpressionVisitor(
                Dependencies.SqlExpressionFactory,
                parametersValues,
                UseRelationalNulls).Process(selectExpression);

            canCache &= optimizerCanCache;

            var fromSqlParameterOptimized = new FromSqlParameterApplyingExpressionVisitor(
                Dependencies.SqlExpressionFactory,
                Dependencies.TypeMappingSource,
                Dependencies.ParameterNameGeneratorFactory.Create(),
                parametersValues).Visit(sqlExpressionOptimized);

            if (!ReferenceEquals(sqlExpressionOptimized, fromSqlParameterOptimized))
            {
                canCache = false;
            }

            return((SelectExpression)fromSqlParameterOptimized, canCache);
        }
コード例 #4
0
            public SelectExpression Optimize(SelectExpression selectExpression, IReadOnlyDictionary <string, object> parametersValues)
            {
                var query = new InExpressionValuesExpandingExpressionVisitor(
                    _sqlExpressionFactory, parametersValues).Visit(selectExpression);

                query = new FromSqlParameterApplyingExpressionVisitor(
                    _sqlExpressionFactory,
                    _parameterNameGeneratorFactory.Create(),
                    parametersValues).Visit(query);

                return((SelectExpression)query);
            }