Skip to content

Commit b6ffe61

Browse files
committed
Revert to more specific handling of situation
Convert.ToString might cover bugs from unintentional usage of other data types and is culture specific
1 parent a07c592 commit b6ffe61

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/NHibernate/Type/AbstractStringType.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ public AbstractStringType(SqlType sqlType)
5757
public override void Set(DbCommand cmd, object value, int index, ISessionImplementor session)
5858
{
5959
var parameter = cmd.Parameters[index];
60-
var stringValue = Convert.ToString(value);
60+
61+
if (value is Enum)
62+
value = Enum.GetName(value.GetType(), value);
6163

6264
//Allow the driver to adjust the parameter for the value
63-
session.Factory.ConnectionProvider.Driver.AdjustParameterForValue(parameter, SqlType, stringValue);
65+
session.Factory.ConnectionProvider.Driver.AdjustParameterForValue(parameter, SqlType, value);
6466

6567
// set the parameter value before the size check, since ODBC changes the size automatically
66-
parameter.Value = stringValue;
68+
parameter.Value = value;
6769

68-
if (parameter.Size > 0 && stringValue.Length > parameter.Size)
70+
if (parameter.Size > 0 && value != null && ((string) value).Length > parameter.Size)
6971
throw new HibernateException("The length of the string value exceeds the length configured in the mapping/parameter.");
7072
}
7173

0 commit comments

Comments
 (0)