Example #1
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments)
        {
            if (!method.Equals(MethodInfo))
            {
                return(null);
            }

            var patternExpression  = arguments[0];
            var endsWithExpression = _fbSqlExpressionFactory.Equal(
                _fbSqlExpressionFactory.Function(
                    "RIGHT",
                    new[] {
                instance,
                _fbSqlExpressionFactory.Function(
                    "CHARACTER_LENGTH",
                    new[] { patternExpression },
                    typeof(int))
            },
                    instance.Type),
                patternExpression);

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? (string)sqlConstantExpression.Value == string.Empty
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : endsWithExpression
                                : _fbSqlExpressionFactory.OrElse(
                       endsWithExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
    public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
    {
        if (!method.Equals(MethodInfo))
        {
            return(null);
        }

        var patternExpression  = _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]);
        var endsWithExpression = _fbSqlExpressionFactory.Equal(
            _fbSqlExpressionFactory.ApplyDefaultTypeMapping(_fbSqlExpressionFactory.Function(
                                                                "RIGHT",
                                                                new[] {
            instance,
            _fbSqlExpressionFactory.Function(
                "CHAR_LENGTH",
                new[] { patternExpression },
                true,
                new[] { true },
                typeof(int))
        },
                                                                true,
                                                                new[] { true, true },
                                                                instance.Type)),
            patternExpression);

        return(patternExpression is SqlConstantExpression sqlConstantExpression
                        ? (string)sqlConstantExpression.Value == string.Empty
                                ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                : endsWithExpression
                        : _fbSqlExpressionFactory.OrElse(
                   endsWithExpression,
                   _fbSqlExpressionFactory.Equal(
                       patternExpression,
                       _fbSqlExpressionFactory.Constant(string.Empty))));
    }
Example #3
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!method.Equals(MethodInfo))
            {
                return(null);
            }

            var patternExpression  = _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]);
            var positionExpression = _fbSqlExpressionFactory.GreaterThan(
                _fbSqlExpressionFactory.Function(
                    "POSITION",
                    new[] { patternExpression, instance },
                    true,
                    new[] { true, true },
                    typeof(int)),
                _fbSqlExpressionFactory.Constant(0));

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? ((string)sqlConstantExpression.Value)?.Length == 0
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : positionExpression
                                : _fbSqlExpressionFactory.OrElse(
                       positionExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments)
        {
            if (!method.Equals(MethodInfo))
            {
                return(null);
            }

            var patternExpression  = arguments[0];
            var positionExpression = _fbSqlExpressionFactory.GreaterThan(
                _fbSqlExpressionFactory.Function(
                    "POSITION",
                    new[] { patternExpression, instance },
                    typeof(int)),
                _fbSqlExpressionFactory.Constant(0));

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? ((string)sqlConstantExpression.Value)?.Length == 0
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : positionExpression
                                : _fbSqlExpressionFactory.OrElse(
                       positionExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!method.Equals(StartsWithMethod))
            {
                return(null);
            }

            var patternExpression = arguments[0];

            var startsWithExpression = _fbSqlExpressionFactory.AndAlso(
                _fbSqlExpressionFactory.Like(
                    instance,
                    _fbSqlExpressionFactory.Add(patternExpression, _fbSqlExpressionFactory.Constant("%"))),
                _fbSqlExpressionFactory.Equal(
                    _fbSqlExpressionFactory.Function(
                        "LEFT",
                        new[] {
                instance,
                _fbSqlExpressionFactory.Function(
                    "CHAR_LENGTH",
                    new[] { patternExpression },
                    true,
                    new[] { true },
                    typeof(int))
            },
                        true,
                        new[] { true, true },
                        instance.Type),
                    patternExpression));

            return(patternExpression is SqlConstantExpression sqlConstantExpression
                                ? (string)sqlConstantExpression.Value == string.Empty
                                        ? (SqlExpression)_fbSqlExpressionFactory.Constant(true)
                                        : startsWithExpression
                                : _fbSqlExpressionFactory.OrElse(
                       startsWithExpression,
                       _fbSqlExpressionFactory.Equal(
                           patternExpression,
                           _fbSqlExpressionFactory.Constant(string.Empty))));
        }
Example #6
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!method.Equals(IsNullOrWhiteSpaceMethod))
            {
                return(null);
            }

            var argument = arguments[0];

            return(_fbSqlExpressionFactory.OrElse(
                       _fbSqlExpressionFactory.IsNull(argument),
                       _fbSqlExpressionFactory.Equal(
                           _fbSqlExpressionFactory.Function("TRIM", new[] { argument }, true, new[] { true }, typeof(string)),
                           _fbSqlExpressionFactory.Constant(string.Empty))
                       ));
        }