Skip to content

Commit b55afb3

Browse files
authored
Npgsql 6: set parameter DbType to DateTime2 when value is not Utc DateTime (nhibernate#3301)
Fixes nhibernate#3291
1 parent 43c5fce commit b55afb3

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/NHibernate/Driver/NpgsqlDriver.cs

+12-3
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)