Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public NpgsqlObjectToStringTranslator(IRelationalTypeMappingSource typeMappingSo
return null;
}

if (instance.TypeMapping?.ClrType == typeof(string))
{
return instance;
}

if (instance.Type == typeof(bool))
{
if (instance.Type == typeof(bool))
Expand Down
11 changes: 11 additions & 0 deletions test/EFCore.PG.FunctionalTests/Query/GearsOfWarQueryNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@ public GearsOfWarQueryNpgsqlTest(GearsOfWarQueryNpgsqlFixture fixture, ITestOutp
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

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
""");
}

#region Byte array

public override async Task Byte_array_filter_by_length_literal_does_not_cast_on_varbinary_n(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ public TPCGearsOfWarQueryNpgsqlTest(TPCGearsOfWarQueryNpgsqlFixture fixture, ITe
Fixture.TestSqlLoggerFactory.SetTestOutputHelper(testOutputHelper);
}

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
""");
}

// Base implementation uses DateTimeOffset.Now, which we don't translate by design. Use DateTimeOffset.UtcNow instead.
public override async Task Select_datetimeoffset_comparison_in_projection(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ public TPTGearsOfWarQueryNpgsqlTest(TPTGearsOfWarQueryNpgsqlFixture fixture, ITe
// TODO: #1232
// protected override bool CanExecuteQueryString => true;

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
""");
}

// Base implementation uses DateTimeOffset.Now, which we don't translate by design. Use DateTimeOffset.UtcNow instead.
public override async Task Select_datetimeoffset_comparison_in_projection(bool async)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,75 @@ SELECT lower(b."String")
""");
}

[ConditionalFact]
public async Task ToString_on_string()
{
await AssertQuery(
ss => ss.Set<BasicTypesEntity>().Where(b => b.String.ToString() == "Seattle").Select(b => b.String));

AssertSql(
"""
SELECT b."String"
FROM "BasicTypesEntities" AS b
WHERE b."String" = 'Seattle'
""");
}

[ConditionalFact]
public async Task ToString_on_nullable_string()
{
await AssertQuery(
ss => ss.Set<NullableBasicTypesEntity>().Where(b => b.String!.ToString() == null).Select(b => b.Id),
ss => ss.Set<NullableBasicTypesEntity>().Where(b => b.String == null).Select(b => b.Id));

AssertSql(
"""
SELECT n."Id"
FROM "NullableBasicTypesEntities" AS n
WHERE n."String" IS NULL
""");
}

[ConditionalFact]
public async Task ToString_on_object_typed_string_grouping_key_order_by()
{
await AssertQuery(
ss => ss.Set<BasicTypesEntity>()
.Where(b => b.String == "Seattle" || b.String == "Berlin")
.GroupBy(b => (object)b.String)
.Select(g => new { Key = g.Key.ToString(), Count = g.Count() })
.OrderBy(g => g.Key),
assertOrder: true);

AssertSql(
"""
SELECT b."String", count(*)::int
FROM "BasicTypesEntities" AS b
WHERE b."String" IN ('Seattle', 'Berlin')
GROUP BY b."String"
ORDER BY b."String" NULLS FIRST
""");
}

[ConditionalFact]
public async Task ToString_on_object_typed_string_grouping_key_where()
{
await AssertQuery(
ss => ss.Set<BasicTypesEntity>()
.GroupBy(b => (object)b.String)
.Select(g => new { Key = g.Key.ToString(), Count = g.Count() })
.Where(g => g.Key == "Seattle"),
elementSorter: g => g.Key);

AssertSql(
"""
SELECT b."String", count(*)::int
FROM "BasicTypesEntities" AS b
GROUP BY b."String"
HAVING b."String" = 'Seattle'
""");
}

#endregion Miscellaneous

#region IndexOf
Expand Down
Loading