/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList <SqlExpression> arguments) { if (_likeMethodInfos.Any(m => Equals(method, m))) { var match = _sqlExpressionFactory.ApplyDefaultTypeMapping(arguments[1]); var pattern = InferStringTypeMappingOrApplyDefault( arguments[2], match.TypeMapping); var excapeChar = arguments.Count == 4 ? InferStringTypeMappingOrApplyDefault( arguments[3], match.TypeMapping) : null; return(_sqlExpressionFactory.Like( match, pattern, excapeChar)); } if (Equals(method, _matchMethodInfo)) { if (arguments[3] is SqlConstantExpression constant) { return(_sqlExpressionFactory.MakeMatch( arguments[1], arguments[2], (MySqlMatchSearchMode)constant.Value)); } if (arguments[3] is SqlParameterExpression parameter) { // Use nested OR clauses here, because MariaDB does not support MATCH...AGAINST from inside of // CASE statements and the nested OR clauses use the fulltext index, while using CASE does not: // <search_mode_1> = @p AND MATCH ... AGAINST ... OR // <search_mode_2> = @p AND MATCH ... AGAINST ... OR [...] var andClauses = Enum.GetValues(typeof(MySqlMatchSearchMode)) .Cast <MySqlMatchSearchMode>() .OrderByDescending(m => m) .Select(m => _sqlExpressionFactory.AndAlso( _sqlExpressionFactory.Equal(parameter, _sqlExpressionFactory.Constant(m)), _sqlExpressionFactory.MakeMatch(arguments[1], arguments[2], m))) .ToArray(); return(andClauses .Skip(1) .Aggregate( andClauses.First(), (currentAnd, previousExpression) => _sqlExpressionFactory.OrElse(previousExpression, currentAnd))); } } return(null); }