@@ -19,28 +19,34 @@ namespace Microsoft.EntityFrameworkCore.Sqlite.Query.Internal
19
19
/// any release. You should only use it directly in your code with extreme caution and knowing that
20
20
/// doing so can result in application failures when updating to a new Entity Framework Core release.
21
21
/// </summary>
22
- public class SqliteRegexTranslator : IMethodCallTranslator
22
+ public class SqliteRegexMethodTranslator : IMethodCallTranslator
23
23
{
24
+ private readonly static MethodInfo _regexIsMatchMethodInfo
25
+ = typeof ( Regex ) . GetRuntimeMethod ( nameof ( Regex . IsMatch ) , new Type [ ] { typeof ( string ) , typeof ( string ) } ) ;
26
+
24
27
private readonly ISqlExpressionFactory _sqlExpressionFactory ;
25
- private readonly static MethodInfo regexIsMatchMethod = typeof ( Regex ) . GetMethod ( nameof ( Regex . IsMatch ) , new Type [ ] { typeof ( string ) , typeof ( string ) } ) ;
26
28
27
29
/// <summary>
28
30
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
29
31
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
30
32
/// any release. You should only use it directly in your code with extreme caution and knowing that
31
33
/// doing so can result in application failures when updating to a new Entity Framework Core release.
32
34
/// </summary>
33
- public SqliteRegexTranslator ( [ NotNull ] ISqlExpressionFactory sqlExpressionFactory )
35
+ public SqliteRegexMethodTranslator ( [ NotNull ] ISqlExpressionFactory sqlExpressionFactory )
34
36
{
37
+ Check . NotNull ( sqlExpressionFactory , nameof ( sqlExpressionFactory ) ) ;
38
+
35
39
_sqlExpressionFactory = sqlExpressionFactory ;
36
40
}
41
+
37
42
/// <summary>
38
43
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
39
44
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
40
45
/// any release. You should only use it directly in your code with extreme caution and knowing that
41
46
/// doing so can result in application failures when updating to a new Entity Framework Core release.
42
47
/// </summary>
43
- public virtual SqlExpression Translate ( SqlExpression instance ,
48
+ public virtual SqlExpression Translate (
49
+ SqlExpression instance ,
44
50
MethodInfo method ,
45
51
IReadOnlyList < SqlExpression > arguments ,
46
52
IDiagnosticsLogger < DbLoggerCategory . Query > logger )
@@ -49,15 +55,22 @@ public virtual SqlExpression Translate(SqlExpression instance,
49
55
Check . NotNull ( arguments , nameof ( arguments ) ) ;
50
56
Check . NotNull ( logger , nameof ( logger ) ) ;
51
57
52
-
53
- if ( method . Equals ( regexIsMatchMethod ) )
58
+ if ( method . Equals ( _regexIsMatchMethodInfo ) )
54
59
{
55
- return _sqlExpressionFactory . Function ( "regexp" ,
56
- new [ ] { arguments [ 1 ] , arguments [ 0 ] } ,
57
- false ,
58
- new [ ] { false , false } ,
59
- typeof ( bool ) ,
60
- arguments [ 0 ] . TypeMapping ) ;
60
+ var input = arguments [ 0 ] ;
61
+ var pattern = arguments [ 1 ] ;
62
+ var stringTypeMapping = ExpressionExtensions . InferTypeMapping ( input , pattern ) ;
63
+
64
+ return _sqlExpressionFactory . Function (
65
+ "regexp" ,
66
+ new [ ]
67
+ {
68
+ _sqlExpressionFactory . ApplyTypeMapping ( pattern , stringTypeMapping ) ,
69
+ _sqlExpressionFactory . ApplyTypeMapping ( input , stringTypeMapping )
70
+ } ,
71
+ nullable : true ,
72
+ argumentsPropagateNullability : new [ ] { true , true } ,
73
+ typeof ( bool ) ) ;
61
74
}
62
75
63
76
return null ;
0 commit comments