public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 {
     if (member.DeclaringType == typeof(DateTime) && member.Name == nameof(DateTime.Date))
     {
         return(_fbSqlExpressionFactory.SpacedFunction(
                    "CAST",
                    new[] { instance, _fbSqlExpressionFactory.Fragment("AS"), _fbSqlExpressionFactory.Fragment("DATE") },
                    true,
                    new[] { true, false, false },
                    typeof(DateTime)));
     }
     return(null);
 }
Пример #2
0
 public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
 {
     if (!TryGetTrimDefinition(instance, method, arguments, out var trimArguments, out var nullability))
     {
         return(null);
     }
     return(_fbSqlExpressionFactory.SpacedFunction(
                "TRIM",
                trimArguments,
                true,
                nullability,
                typeof(string)));
 }
    public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
    {
        if (!MemberMapping.TryGetValue(member, out var part))
        {
            return(null);
        }

        var result = (SqlExpression)_fbSqlExpressionFactory.SpacedFunction(
            "EXTRACT",
            new[] { _fbSqlExpressionFactory.Fragment(part), _fbSqlExpressionFactory.Fragment("FROM"), instance },
            true,
            new[] { false, false, true },
            typeof(int));

        if (part == SecondPart || part == MillisecondPart)
        {
            result = _fbSqlExpressionFactory.Function("TRUNC", new[] { result }, true, new[] { true }, typeof(int));
        }
        return(result);
    }
Пример #4
0
        public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger)
        {
            if (!(method.Equals(SubstringOnlyStartMethod) || method.Equals(SubstringStartAndLengthMethod)))
            {
                return(null);
            }

            var fromExpression     = _fbSqlExpressionFactory.ApplyDefaultTypeMapping(_fbSqlExpressionFactory.Add(arguments[0], _fbSqlExpressionFactory.Constant(1)));
            var forExpression      = arguments.Count == 2 ? _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]) : null;
            var substringArguments = forExpression != null
                                ? new[] { instance, _fbSqlExpressionFactory.Fragment("FROM"), fromExpression, _fbSqlExpressionFactory.Fragment("FOR"), forExpression }
                                : new[] { instance, _fbSqlExpressionFactory.Fragment("FROM"), fromExpression };
            var nullability = forExpression != null
                                ? new[] { true, false, true, false, true }
                                : new[] { true, false, true };

            return(_fbSqlExpressionFactory.SpacedFunction(
                       "SUBSTRING",
                       substringArguments,
                       true,
                       nullability,
                       typeof(string)));
        }