We're getting started with plugging in (Fluent) NHibernate 2.1.2 onto a legacy ASP.NET application.
Previously we've been connecting to an Oracle 9 database using System.Data.OracleClient, but because of some requirements (namely with using Oracle SPs with HBM maps), it seems that at least for the NH component, we'll have to adapt the Oracle.DataAccess.dll instead.
For the most part, we've managed to get that bit working by doing the following:
- Adding and referencing the 9.2.0.700 Oracle.DataAccess.dll into the data layer.
- Qualifying the Oracle.DataAccess assembly via the web.config. [via]
- Adding OraOps9.dll into the application, and setting it to Embedded Resource.
The last step, we've done because our version of the ODP references it, but we have limited capacity to make sure that it will be present on the production server eventually.
This eventually led to getting an InvalidCastException:
Unable to cast object of type 'Oracle.DataAccess.Client.OracleConnection' to type 'System.Data.Common.DbConnection'
Sifting around for a solution, the status quo seemed to be to ensure that the hbm2dll.keywords
property in the NH configuration was set to none
. I've done that in both a dynamically created config, and the fluent call to create a SessionFactory.
NHibernate.Cfg.Configuration cfg =
new NHibernate.Cfg.Configuration()
.SetProperty("dialect", "NHibernate.Dialect.Oracle9iDialect")
.SetProperty("connection.driver_class", "NHibernate.Driver.OracleDataClientDriver")
.SetProperty("connection.connection_string",conn)
.SetProperty("connection.provider","NHibernate.Connection.DriverConnectionProvider")
.SetProperty("hbm2dll.keywords","none")
;
_sessionFactory = Fluently.Configure(cfg)
.Database ( OracleDataClientConfiguration.Oracle9.ConnectionString(conn) )
.Mappings ( x => x.FluentMappings.AddFromAssemblyOf<MyDL>() )
.Mappings ( x => x.HbmMappings.AddFromAssemblyOf<MyEntity>() )
.ExposeConfiguration(x => x.Properties.Add("hbm2dll.keywords", "none"))
.BuildSessionFactory()
;
But even so, I still get the same InvalidCastException.
Is there anything else that could be causing this? Are any of my calls above accidentally tripping the hbm2dll.keywords
property value back to something else? Any ideas?