public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments) { if (!(method.Equals(SubstringOnlyStartMethod) || method.Equals(SubstringStartAndLengthMethod))) { return(null); } var fromExpression = _fbSqlExpressionFactory.Add(arguments[0], _fbSqlExpressionFactory.Constant(1)); var forExpression = arguments.Count == 2 ? arguments[1] : null; return(_fbSqlExpressionFactory.Substring(instance, fromExpression, forExpression)); }
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.Extract(part, instance); if (part == YearDayPart) { result = _fbSqlExpressionFactory.Add(result, _fbSqlExpressionFactory.Constant(1)); } return(result); }
public SqlExpression Translate(SqlExpression instance, MemberInfo member, Type returnType) { if (!MemberDatePartMapping.TryGetValue(member, out var part)) { return(null); } var result = (SqlExpression)_fbSqlExpressionFactory.Extract(part, instance); if (part == YearDayPart) { result = _fbSqlExpressionFactory.Add(result, _fbSqlExpressionFactory.Constant(1)); } return(result); }
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 == YearDayPart) { result = _fbSqlExpressionFactory.Add(result, _fbSqlExpressionFactory.Constant(1)); } return(result); }
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)))); }
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))); }