Skip to content
Open
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 @@ -72,6 +72,8 @@ public class NpgsqlNodaTimeMethodCallTranslator : IMethodCallTranslator
private static readonly MethodInfo LocalDateTime_Distance =
typeof(NpgsqlNodaTimeDbFunctionsExtensions).GetRuntimeMethod(
nameof(NpgsqlNodaTimeDbFunctionsExtensions.Distance), new[] { typeof(DbFunctions), typeof(LocalDateTime), typeof(LocalDateTime) })!;
private static readonly MethodInfo LocalDateTime_ToDateTimeUnspecified =
typeof(LocalDateTime).GetRuntimeMethod(nameof(LocalDateTime.ToDateTimeUnspecified), Type.EmptyTypes)!;

private static readonly MethodInfo LocalDate_Distance =
typeof(NpgsqlNodaTimeDbFunctionsExtensions).GetRuntimeMethod(
Expand Down Expand Up @@ -253,6 +255,14 @@ public NpgsqlNodaTimeMethodCallTranslator(
return _sqlExpressionFactory.MakePostgresBinary(PostgresExpressionType.Distance, arguments[1], arguments[2]);
}

if (method == LocalDateTime_ToDateTimeUnspecified)
{
return _sqlExpressionFactory.Convert(
instance!,
typeof(DateTime),
_typeMappingSource.FindMapping(typeof(DateTime), "timestamp without time zone"));
}

return null;
}

Expand Down
18 changes: 18 additions & 0 deletions test/EFCore.PG.NodaTime.FunctionalTests/NodaTimeQueryNpgsqlTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,24 @@ LIMIT 1
""");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public async Task LocalDateTime_ToDateTimeUnspecified(bool async)
{
await AssertQuery(
async,
ss => ss.Set<NodaTimeTypes>()
.Where(t => t.LocalDateTime.ToDateTimeUnspecified() == new DateTime(2018, 4, 20, 10, 31, 33, 666)),
entryCount: 1);

AssertSql(
"""
SELECT n."Id", n."DateInterval", n."Duration", n."Instant", n."InstantRange", n."Interval", n."LocalDate", n."LocalDate2", n."LocalDateRange", n."LocalDateTime", n."LocalTime", n."Long", n."OffsetTime", n."Period", n."TimeZoneId", n."ZonedDateTime"
FROM "NodaTimeTypes" AS n
WHERE n."LocalDateTime"::timestamp = TIMESTAMP '2018-04-20 10:31:33.666'
""");
}

#endregion LocalDateTime

#region LocalDate
Expand Down