Skip to content

NH-4017 - Handle Time parameter conversion for newer Npgsql #631

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

Closed
Closed
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions src/NHibernate/Driver/NpgsqlDriver.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Data;
using System.Data.Common;
using System.Linq;

namespace NHibernate.Driver
{
Expand Down Expand Up @@ -84,5 +86,19 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
if (sqlType.DbType == DbType.Currency)
dbParam.DbType = DbType.Decimal;
}

public override void AdjustCommand(DbCommand command)
{
if (DriverVersion?.Major < 3)
// Prior to v3, Npgsql was expecting DateTime for time. Nothing to do.
// https://github.com/npgsql/npgsql/issues/347
return;

foreach (var parameter in command.Parameters.Cast<DbParameter>().Where(x => x.DbType == DbType.Time))
{
if (parameter.Value is DateTime dateTimeValue)
parameter.Value = dateTimeValue.TimeOfDay;
}
}
}
}
7 changes: 7 additions & 0 deletions src/NHibernate/Driver/ReflectionBasedDriver.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Data.Common;
using NHibernate.Util;

Expand All @@ -12,6 +13,11 @@ public abstract class ReflectionBasedDriver : DriverBase

private readonly IDriveConnectionCommandProvider connectionCommandProvider;

/// <summary>
/// If the driver use a third party driver (not a .Net Framework DbProvider), its assembly version.
/// </summary>
protected Version DriverVersion { get; }

/// <summary>
/// Initializes a new instance of <see cref="ReflectionBasedDriver" /> with
/// type names that are loaded from the specified assembly.
Expand Down Expand Up @@ -51,6 +57,7 @@ protected ReflectionBasedDriver(string providerInvariantName, string driverAssem
else
{
connectionCommandProvider = new ReflectionDriveConnectionCommandProvider(connectionType, commandType);
DriverVersion = connectionType.Assembly.GetName().Version;
}
}

Expand Down