From dba77fd16bf29d825caf5a5c6f78365b43393326 Mon Sep 17 00:00:00 2001 From: Shay Rojansky Date: Fri, 28 Jun 2024 15:01:28 +0200 Subject: [PATCH] Correct non-NodaTime date/time type mappings when NodaTime is configured (#3214) Fixes #3213 --- .../Internal/NpgsqlDateTimeMemberTranslator.cs | 4 ++-- .../Internal/NpgsqlDateTimeMethodTranslator.cs | 6 +++--- src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMemberTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMemberTranslator.cs index e9d54f133..73c2b578f 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMemberTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMemberTranslator.cs @@ -27,8 +27,8 @@ public class NpgsqlDateTimeMemberTranslator : IMemberTranslator public NpgsqlDateTimeMemberTranslator(IRelationalTypeMappingSource typeMappingSource, NpgsqlSqlExpressionFactory sqlExpressionFactory) { _typeMappingSource = typeMappingSource; - _timestampMapping = typeMappingSource.FindMapping("timestamp without time zone")!; - _timestampTzMapping = typeMappingSource.FindMapping("timestamp with time zone")!; + _timestampMapping = typeMappingSource.FindMapping(typeof(DateTime), "timestamp without time zone")!; + _timestampTzMapping = typeMappingSource.FindMapping(typeof(DateTime), "timestamp with time zone")!; _sqlExpressionFactory = sqlExpressionFactory; } diff --git a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs index e64192022..101ae9b19 100644 --- a/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs +++ b/src/EFCore.PG/Query/ExpressionTranslators/Internal/NpgsqlDateTimeMethodTranslator.cs @@ -113,9 +113,9 @@ public NpgsqlDateTimeMethodTranslator( { _typeMappingSource = typeMappingSource; _sqlExpressionFactory = sqlExpressionFactory; - _timestampMapping = typeMappingSource.FindMapping("timestamp without time zone")!; - _timestampTzMapping = typeMappingSource.FindMapping("timestamp with time zone")!; - _intervalMapping = typeMappingSource.FindMapping("interval")!; + _timestampMapping = typeMappingSource.FindMapping(typeof(DateTime), "timestamp without time zone")!; + _timestampTzMapping = typeMappingSource.FindMapping(typeof(DateTime), "timestamp with time zone")!; + _intervalMapping = typeMappingSource.FindMapping(typeof(TimeSpan), "interval")!; _textMapping = typeMappingSource.FindMapping("text")!; } diff --git a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs index cff84bdb2..5129fdb7c 100644 --- a/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs +++ b/src/EFCore.PG/Storage/Internal/NpgsqlTypeMappingSource.cs @@ -11,7 +11,6 @@ using System.Text.Json; using Npgsql.EntityFrameworkCore.PostgreSQL.Infrastructure.Internal; using Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.Mapping; -using Npgsql.Internal; namespace Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal;