Unable to save NVARCHAR2 column in Oracle (using ODP.NET)

Description

When trying to save a NVARCHAR2 column (NVARCHAR2 is a column used in Oracle, to store Unicode string value in a non-Unicode database) with NHibernate, the data is not stored correctly (data stored is '?????').

The reason for that is the parameter built in NHibernate is setting the parameter type to be DbType.String"
OracleParameter.DbType = DbType.String;

In order to work with ODP.NET correctly you need to change the OracleDbType property, like this:
OracleParameter.OracleDbType = OracleDbType.NVarchar2;

The way I found to change this was on the OracleDataClientDriver class, on the InitializeParameter procedure, using reflection (because NHibernate does not have a reference to ODP.NET) like this:

switch (sqlType.DbType)
{
case DbType.String:
dbParam.ParameterName = FormatNameForParameter(name);
System.Type objType = dbParam.GetType();
PropertyInfo propIfo = objType.GetProperty("OracleDbType");
Object val = System.Enum.Parse(propInfo.PropertyType, "NVarchar2");
propInfo.SetValue(dbParam, val, null)
break;
}

This works for me, is there a better place where this could be handled?

Environment

None

Assignee

Unassigned

Reporter

Tomer Avissar

Labels

None

Components

Affects versions

Priority

Minor
Configure