Skip to content

Commit 27a7a7b

Browse files
hazzikfredericDelaporte
authored andcommitted
Backport Npgsql 6 parameter DbType handling for datetime (nhibernate#3301)
Fixes nhibernate#3291
1 parent 0d9d46b commit 27a7a7b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/NHibernate/Driver/NpgsqlDriver.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,19 @@ public override void AdjustCommand(DbCommand command)
8888
for (var i = 0; i < command.Parameters.Count; i++)
8989
{
9090
var parameter = command.Parameters[i];
91-
if (parameter.Value is DateTime)
91+
if (parameter.DbType == DbType.DateTime &&
92+
parameter.Value is DateTime dateTime &&
93+
dateTime.Kind != DateTimeKind.Utc)
9294
{
93-
// Let Npgsql 6 driver to decide parameter type
94-
parameter.ResetDbType();
95+
// There are breaking changes in Npgsql 6 as following:
96+
// UTC DateTime is now strictly mapped to timestamptz,
97+
// while Local/Unspecified DateTime is now strictly mapped to timestamp.
98+
//
99+
// DbType.DateTime now maps to timestamptz, not timestamp.
100+
// DbType.DateTime2 continues to map to timestamp
101+
//
102+
// See more details here: https://www.npgsql.org/doc/release-notes/6.0.html#detailed-notes
103+
parameter.DbType = DbType.DateTime2;
95104
}
96105
}
97106
}

0 commit comments

Comments
 (0)