You could use NVARCHAR2 for all strings in your app if they are all NVARCHAR2 in the DB (otherwise you might get performance problems because of conversions to VARCHAR2) - but you need at least NHibernate 5.0 for it. Set this prop in NHibernate config to true: oracle.use_n_prefixed_types_for_unicode
nHibernateConfig.SetProperty("oracle.use_n_prefixed_types_for_unicode", "true");
A better solution, if you have mixed VARCHAR2 and NVARCHAR2 columns, is to use a custom type for NVARCHAR2 columns/properties:
public class UnicodeStringType : IUserType
{
public bool Equals(object x, object y)
{
if (ReferenceEquals(x, y)) return true;
if (x == null || y == null) return false;
return x.Equals(y);
}
public int GetHashCode(object x)
{
return x.GetHashCode();
}
public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
var value = NHibernateUtil.String.NullSafeGet(rs, names[0]) as string;
return value;
}
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
var parameter = (IDataParameter)cmd.Parameters[index];
((OracleParameter)parameter).OracleDbType = OracleDbType.NVarchar2;
parameter.Value = value;
}
public object DeepCopy(object value)
{
return value;
}
public object Replace(object original, object target, object owner)
{
return original;
}
public object Assemble(object cached, object owner)
{
return DeepCopy(cached);
}
public object Disassemble(object value)
{
return DeepCopy(value);
}
public SqlType[] SqlTypes => new[] { new SqlType(DbType.String) };
public Type ReturnedType => typeof(string);
public bool IsMutable => false;
}
You use it like this in mappings:
Map((x) => x.Symbol).Column("SYMBOL").CustomType<UnicodeStringType>().Not.Nullable();