Skip to content

Commit

Permalink
fixup! Clean up PR dotnet#22497
Browse files Browse the repository at this point in the history
Fix type mapping
  • Loading branch information
bricelam committed Oct 30, 2020
1 parent 050f647 commit 576be14
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,20 @@ public virtual SqlExpression Translate(

if (method.Equals(_regexIsMatchMethodInfo))
{
var input = arguments[0];
var pattern = arguments[1];
var stringTypeMapping = ExpressionExtensions.InferTypeMapping(input, pattern);

return _sqlExpressionFactory.Function(
"regexp",
new[] { arguments[1], arguments[0] },
new[]
{
_sqlExpressionFactory.ApplyTypeMapping(pattern, stringTypeMapping),
_sqlExpressionFactory.ApplyTypeMapping(input, stringTypeMapping)
},
nullable: true,
argumentsPropagateNullability: new[] { true, true },
typeof(bool),
arguments[0].TypeMapping);
typeof(bool));
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,11 @@ public override Task Regex_IsMatch_MethodCall(bool async)
return AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall(async));
}

public override Task Regex_IsMatch_MethodCall_constant_input(bool async)
{
return AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall_constant_input(async));
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1592,8 +1592,18 @@ public virtual Task Regex_IsMatch_MethodCall(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>().Where(o => Regex.IsMatch(o.CustomerID, @"^T")),
ss => ss.Set<Customer>().Where(o => Regex.IsMatch(o.CustomerID, "^T")),
entryCount: 6);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Regex_IsMatch_MethodCall_constant_input(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>().Where(o => Regex.IsMatch("ALFKI", o.CustomerID)),
entryCount: 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1554,6 +1554,11 @@ public override Task Regex_IsMatch_MethodCall(bool async)
return AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall(async));
}

public override Task Regex_IsMatch_MethodCall_constant_input(bool async)
{
return AssertTranslationFailed(() => base.Regex_IsMatch_MethodCall_constant_input(async));
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,15 @@ public override async Task Regex_IsMatch_MethodCall(bool async)
WHERE regexp('^T', ""c"".""CustomerID"")");
}

public override async Task Regex_IsMatch_MethodCall_constant_input(bool async)
{
await base.Regex_IsMatch_MethodCall_constant_input(async);

AssertSql(@"SELECT ""c"".""CustomerID"", ""c"".""Address"", ""c"".""City"", ""c"".""CompanyName"", ""c"".""ContactName"", ""c"".""ContactTitle"", ""c"".""Country"", ""c"".""Fax"", ""c"".""Phone"", ""c"".""PostalCode"", ""c"".""Region""
FROM ""Customers"" AS ""c""
WHERE regexp(""c"".""CustomerID"", ""ALFKI"")");
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);
}
Expand Down

0 comments on commit 576be14

Please sign in to comment.