Skip to content

Commit

Permalink
ToString() on string columns added (#29349)
Browse files Browse the repository at this point in the history
Fixes #20839
  • Loading branch information
bikbov authored Nov 9, 2022
1 parent 7302231 commit d4aa1ea
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public SqlServerObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFact
return null;
}

if(instance.TypeMapping is not null && instance.TypeMapping.ClrType == typeof(string))
{
return instance;
}

if (instance.Type == typeof(bool))
{
if (instance is ColumnExpression columnExpression && columnExpression.IsNullable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public SqliteObjectToStringTranslator(ISqlExpressionFactory sqlExpressionFactory
return null;
}

if (instance.TypeMapping is not null && instance.TypeMapping.ClrType == typeof(string))
{
return instance;
}

if (instance.Type == typeof(bool))
{
if (instance is ColumnExpression columnExpression && columnExpression.IsNullable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public virtual Task ToString_guid_property_projection(bool async)
Assert.Equal(e.B.ToLower(), a.B.ToLower());
});

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task ToString_string_property_projection(bool async)
=> AssertQuery(
async,
ss => ss.Set<Weapon>().Select(w => w.Name.ToString()));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task ToString_boolean_property_non_nullable(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4095,6 +4095,15 @@ FROM [Gears] AS [g]
""");
}

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

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] AS [w]");
}


public override async Task ToString_boolean_property_non_nullable(bool async)
{
await base.ToString_boolean_property_non_nullable(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12495,6 +12495,14 @@ FROM [Weapons] AS [w]
""");
}

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

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] AS [w]");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
{
await base.ToString_boolean_property_non_nullable(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10734,6 +10734,14 @@ FROM [Weapons] AS [w]
""");
}

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

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] AS [w]");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
{
await base.ToString_boolean_property_non_nullable(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9004,6 +9004,14 @@ ELSE NULL
""");
}

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

AssertSql(@"SELECT [w].[Name]
FROM [Weapons] FOR SYSTEM_TIME AS OF '2010-01-01T00:00:00.0000000' AS [w]");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
{
await base.ToString_boolean_property_non_nullable(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3091,6 +3091,14 @@ SELECT COALESCE(SUM("g"."SquadId"), 0)
""");
}

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

AssertSql(@"SELECT ""w"".""Name""
FROM ""Weapons"" AS ""w""");
}

public override async Task ToString_boolean_property_non_nullable(bool async)
{
await base.ToString_boolean_property_non_nullable(async);
Expand Down

0 comments on commit d4aa1ea

Please sign in to comment.