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

Activity

Show:
Fabio Maulo
December 8, 2010, 3:59 PM

You have to do two things.
The one you have already done and then create a specific IType;
then, in your implementation of your custom OracleDrive you can apply the specific parameter type only in presence of your IType.

We can't add a reference to Oracle stuff.
Would be very useful is you can share your solution in the www.nhforge.org wiki with others Oracle users.
Thanks.

Assignee

Unassigned

Reporter

Tomer Avissar

Labels

None

Components

Affects versions

Priority

Minor
Configure