Skip to content

Commit e8c8a3b

Browse files
committed
Localize changes to AbstractStringType
1 parent 82f9f54 commit e8c8a3b

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

src/NHibernate.Test/NHSpecificTest/GH2621Enum/Fixture.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@ public class Fixture : BugTestCase
77
[Test]
88
public void TestOk()
99
{
10-
using (ISession s = OpenSession())
10+
using (var s = OpenSession())
11+
using (s.BeginTransaction())
1112
{
12-
using (ITransaction t = s.BeginTransaction())
13-
{
14-
var query = s.CreateQuery(@"
15-
SELECT Name FROM NHibernate.Test.NHSpecificTest.GH2621Enum.ClassWithString ROOT WHERE ROOT.Kind = :kind");
16-
query.SetParameter("kind", Kind.SomeKind);
17-
Assert.DoesNotThrow(() => query.List());
18-
}
13+
var query = s.CreateQuery(
14+
@"SELECT Name FROM NHibernate.Test.NHSpecificTest.GH2621Enum.ClassWithString ROOT WHERE ROOT.Kind = :kind");
15+
query.SetParameter("kind", Kind.SomeKind);
16+
Assert.DoesNotThrow(() => query.List());
1917
}
2018
}
2119
}

src/NHibernate/Driver/MicrosoftDataSqlClientDriver.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ public MicrosoftDataSqlClientDriver()
7575
/// <inheritdoc />
7676
public virtual void AdjustParameterForValue(DbParameter parameter, SqlType sqlType, object value)
7777
{
78-
if (value is Enum)
79-
value = Enum.GetName(value.GetType(), value);
80-
8178
if (value is string stringVal)
8279
switch (parameter.DbType)
8380
{

src/NHibernate/Driver/SqlClientDriver.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,6 @@ public override bool SupportsMultipleQueries
320320

321321
public virtual void AdjustParameterForValue(DbParameter parameter, SqlType sqlType, object value)
322322
{
323-
if (value is Enum)
324-
value = Enum.GetName(value.GetType(), value);
325-
326323
if (value is string stringVal)
327324
{
328325
switch (parameter.DbType)

src/NHibernate/Type/AbstractStringType.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,23 @@ public override void Set(DbCommand cmd, object value, int index, ISessionImpleme
5858
{
5959
var parameter = cmd.Parameters[index];
6060

61-
//Allow the driver to adjust the parameter for the value
62-
session.Factory.ConnectionProvider.Driver.AdjustParameterForValue(parameter, SqlType, value);
61+
if (value == null)
62+
{
63+
parameter.Value = DBNull.Value;
64+
}
65+
else
66+
{
67+
var stringValue = Convert.ToString(value);
68+
69+
//Allow the driver to adjust the parameter for the value
70+
session.Factory.ConnectionProvider.Driver.AdjustParameterForValue(parameter, SqlType, stringValue);
6371

64-
// set the parameter value before the size check, since ODBC changes the size automatically
65-
parameter.Value = value;
72+
// set the parameter value before the size check, since ODBC changes the size automatically
73+
parameter.Value = stringValue;
6674

67-
if (parameter.Size > 0 && value != null && Convert.ToString(value).Length > parameter.Size)
68-
throw new HibernateException("The length of the string value exceeds the length configured in the mapping/parameter.");
75+
if (parameter.Size > 0 && stringValue.Length > parameter.Size)
76+
throw new HibernateException("The length of the string value exceeds the length configured in the mapping/parameter.");
77+
}
6978
}
7079

7180
public override object Get(DbDataReader rs, int index, ISessionImplementor session)

0 commit comments

Comments
 (0)