From e50fdcf411dfcb1929309fbeccb2e8e638cf267a Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Tue, 9 May 2023 13:41:57 +1000 Subject: [PATCH] Make check more specific --- src/NHibernate/Driver/NpgsqlDriver.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/NHibernate/Driver/NpgsqlDriver.cs b/src/NHibernate/Driver/NpgsqlDriver.cs index 69c39821e1c..9a4a4b06771 100644 --- a/src/NHibernate/Driver/NpgsqlDriver.cs +++ b/src/NHibernate/Driver/NpgsqlDriver.cs @@ -88,10 +88,19 @@ public override void AdjustCommand(DbCommand command) for (var i = 0; i < command.Parameters.Count; i++) { var parameter = command.Parameters[i]; - if (parameter.Value is DateTime) + if (parameter.DbType == DbType.DateTime && + parameter.Value is DateTime dateTime && + dateTime.Kind != DateTimeKind.Utc) { - // Let Npgsql 6 driver to decide parameter type - parameter.ResetDbType(); + // There are breaking changes in Npgsql 6 as following: + // UTC DateTime is now strictly mapped to timestamptz, + // while Local/Unspecified DateTime is now strictly mapped to timestamp. + // + // DbType.DateTime now maps to timestamptz, not timestamp. + // DbType.DateTime2 continues to map to timestamp + // + // See more details here: https://www.npgsql.org/doc/release-notes/6.0.html#detailed-notes + parameter.DbType = DbType.DateTime2; } } }