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); }
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); }
public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, IDiagnosticsLogger <DbLoggerCategory.Query> logger) { if (!MethodInfoDatePartMapping.TryGetValue(method, out var part)) { return(null); } return(_fbSqlExpressionFactory.Function( "DATEADD", new[] { _fbSqlExpressionFactory.Fragment(part), arguments[0], instance }, true, new[] { default, true, true },
public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments) { if (!MethodInfoDatePartMapping.TryGetValue(method, out var part)) { return(null); } return(_fbSqlExpressionFactory.Function( "DATEADD", new[] { _fbSqlExpressionFactory.Fragment(part), arguments[0], instance }, instance.Type)); }
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))); }
bool TryGetTrimDefinition(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments, out IEnumerable <SqlExpression> trimArguments, out IEnumerable <bool> nullability) { if (method.Equals(TrimWithoutArgsMethod)) { trimArguments = new[] { _fbSqlExpressionFactory.Fragment("BOTH"), _fbSqlExpressionFactory.Fragment("FROM"), instance }; nullability = new[] { false, false, true }; return(true); } if (method.Equals(TrimWithCharArgMethod)) { trimArguments = new[] { _fbSqlExpressionFactory.Fragment("BOTH"), _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]), _fbSqlExpressionFactory.Fragment("FROM"), instance }; nullability = new[] { false, true, false, true }; return(true); } if (method.Equals(TrimEndWithoutArgsMethod)) { trimArguments = new[] { _fbSqlExpressionFactory.Fragment("TRAILING"), _fbSqlExpressionFactory.Fragment("FROM"), instance }; nullability = new[] { false, false, true }; return(true); } if (method.Equals(TrimEndWithCharArgMethod)) { trimArguments = new[] { _fbSqlExpressionFactory.Fragment("TRAILING"), _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]), _fbSqlExpressionFactory.Fragment("FROM"), instance }; nullability = new[] { false, true, false, true }; return(true); } if (method.Equals(TrimStartWithoutArgsMethod)) { trimArguments = new[] { _fbSqlExpressionFactory.Fragment("LEADING"), _fbSqlExpressionFactory.Fragment("FROM"), instance }; nullability = new[] { false, false, true }; return(true); } if (method.Equals(TrimStartWithCharArgMethod)) { trimArguments = new[] { _fbSqlExpressionFactory.Fragment("LEADING"), _fbSqlExpressionFactory.ApplyDefaultTypeMapping(arguments[0]), _fbSqlExpressionFactory.Fragment("FROM"), instance }; nullability = new[] { false, true, false, true }; return(true); } trimArguments = default; nullability = default; return(false); }