Skip to content

Commit cf61f34

Browse files
NH-3078 - trying its solution for PostgreSQL
1 parent 3adb353 commit cf61f34

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/NHibernate/Driver/NpgsqlDriver.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,5 @@ protected override void InitializeParameter(DbParameter dbParam, string name, Sq
8686
if (sqlType.DbType == DbType.Currency)
8787
dbParam.DbType = DbType.Decimal;
8888
}
89-
90-
public override void AdjustCommand(DbCommand command)
91-
{
92-
if (DriverVersion?.Major < 3)
93-
// Prior to v3, Npgsql was expecting DateTime for time. Nothing to do.
94-
// https://github.com/npgsql/npgsql/issues/347
95-
return;
96-
97-
foreach (var parameter in command.Parameters.Cast<DbParameter>().Where(x => x.DbType == DbType.Time))
98-
{
99-
if (parameter.Value is DateTime dateTimeValue)
100-
parameter.Value = dateTimeValue.TimeOfDay;
101-
}
102-
}
10389
}
10490
}

src/NHibernate/Type/TimeAsTimeSpanType.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,15 @@ public override object Get(DbDataReader rs, string name)
6262

6363
public override void Set(DbCommand st, object value, int index)
6464
{
65-
DateTime date = BaseDateValue.AddTicks(((TimeSpan)value).Ticks);
66-
st.Parameters[index].Value = date;
65+
if (st.Parameters[index].DbType == DbType.DateTime)
66+
{
67+
var date = BaseDateValue.AddTicks(((TimeSpan)value).Ticks);
68+
st.Parameters[index].Value = date;
69+
}
70+
else
71+
{
72+
st.Parameters[index].Value = value;
73+
}
6774
}
6875

6976
public override System.Type ReturnedClass

0 commit comments

Comments
 (0)