Skip to content

Commit

Permalink
Cleanup PR dotnet#19473
Browse files Browse the repository at this point in the history
Resolves dotnet#17223
  • Loading branch information
smitpatel committed Oct 30, 2020
1 parent 1e0bdda commit acfb88d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Reflection;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
using Microsoft.EntityFrameworkCore.Utilities;
Expand All @@ -21,23 +22,23 @@ public class SqliteObjectToStringTranslator : IMethodCallTranslator
{
private static readonly HashSet<Type> _typeMapping = new HashSet<Type>
{
typeof(int),
typeof(long),
typeof(Guid),
typeof(bool),
typeof(byte),
typeof(byte[]),
typeof(char),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(decimal),
typeof(double),
typeof(float),
typeof(char),
typeof(Guid),
typeof(int),
typeof(long),
typeof(sbyte),
typeof(short),
typeof(DateTime),
typeof(DateTimeOffset),
typeof(TimeSpan),
typeof(uint),
typeof(ushort),
typeof(sbyte),
typeof(bool),
};

private readonly ISqlExpressionFactory _sqlExpressionFactory;
Expand All @@ -57,15 +58,19 @@ public SqliteObjectToStringTranslator([NotNull] ISqlExpressionFactory sqlExpress
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual SqlExpression Translate(SqlExpression instance, MethodInfo method, IReadOnlyList<SqlExpression> arguments)
public virtual SqlExpression Translate(
SqlExpression instance,
MethodInfo method,
IReadOnlyList<SqlExpression> arguments,
IDiagnosticsLogger<DbLoggerCategory.Query> logger)
{
Check.NotNull(method, nameof(method));
Check.NotNull(arguments, nameof(arguments));

return method.Name == nameof(ToString)
&& arguments.Count == 0
&& instance != null
&& _typeMapping.Contains(instance.Type.UnwrapNullableType())
&& _typeMapping.Contains(instance.Type)
? _sqlExpressionFactory.Convert(instance, typeof(string))
: null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public ConvertToProviderTypesSqliteTest(ConvertToProviderTypesSqliteFixture fixt
//fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

public override void Object_to_string_conversion()
{
// Return values are not string
}

public class ConvertToProviderTypesSqliteFixture : ConvertToProviderTypesFixtureBase
{
public override bool StrictEquality
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ public override void Where_bool_gets_converted_to_equality_when_value_conversion
WHERE ""b"".""IndexerVisible"" <> 'Aye'");
}

public override void Object_to_string_conversion()
{
// Return values are not string
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,15 @@ public override async Task Decimal_cast_to_double_works(bool async)
WHERE CAST(""p"".""UnitPrice"" AS REAL) > 100.0");
}

[ConditionalTheory(Skip = "Issue#17223")]
public override Task Like_with_non_string_column_using_ToString(bool async)
=> base.Like_with_non_string_column_using_ToString(async);
public override async Task Like_with_non_string_column_using_ToString(bool async)
{
await base.Like_with_non_string_column_using_ToString(async);

AssertSql(
@"SELECT ""o"".""OrderID"", ""o"".""CustomerID"", ""o"".""EmployeeID"", ""o"".""OrderDate""
FROM ""Orders"" AS ""o""
WHERE CAST(""o"".""OrderID"" AS TEXT) LIKE '%20%'");
}

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

0 comments on commit acfb88d

Please sign in to comment.