Skip to content

Npgsql 6: set parameter DbType to DateTime2 when value is not Utc DateTime #3301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2023
Merged
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
15 changes: 12 additions & 3 deletions src/NHibernate/Driver/NpgsqlDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down