A few days into a new project: C#, Oracle, ASP.Net, .Net 4, VS 2010. After creating a (very!) basic data model with a couple of tables, the first task was to check whether the intended tools (C# 4, NHibernate+Fluent, ODP.Net, Oracle 11g) can be persuaded to co-operate.
Versions of tools and libraries used:
After I had defined my classes and maps as described in Fluent’s Getting Started wiki page, the first major hurdle was to get the session factory builder to execute without exception:
public static ISessionFactory Configure()
var c = Fluently.Configure();
.ConnectionString(x => x.FromConnectionStringWithKey("default"))
c.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ConfigureDAL>());
Creating an NHibernate session factory with Fluent, connecting to an Oracle database via ODP.Net.
Fluent provides 3 classes for Oracle access in the FluentNHibernate.Cfg.Db namespace:
- OracleClientConfiguration for the MS Oracle Client (System.Data.OracleClient, deprecated)
- OracleConfiguration, obsolete and replaced by:
- OracleDataClientConfiguration for use with ODP
The connection string is stored in app.config under the name “default”:
(SERVICE_NAME=orcl)));User Id=cpa;Password=the_password;" />
Trying to execute the BuildSessionFactory() method raised the first exception:
The element ‘class’ in namespace ‘urn:nhibernate-mapping-2.2’ has invalid child element ‘property’ in namespace ‘urn:nhibernate-mapping-2.2’. List of possible elements expected: ‘meta, subselect, cache, synchronize, comment, tuplizer, id, composite-id’
I tried to step through the source code, and noticed that the downloaded source code version did not match the installed 1.0 RTM of Fluent. So I updated to build 636, which solved this problem, but raised a new one:
The IDbCommand and IDbConnection implementation in the assembly Oracle.DataAccess could not be found.
Ensure that the assembly Oracle.DataAccess is located in the application directory or in the Global Assembly Cache.
If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly.
Thanks to the interweb I found this blog which provided the solution: Force .Net to load a specific version of ODP (126.96.36.199 in my case), instead of looking for any version:
fullName="Oracle.DataAccess, Version=188.8.131.52, Culture=neutral,
Start the Visual Studio prompt and type
gacutil /l | find "Oracle"
to find out which version of ODP you have installed. The assemblies come in a version for .Net 1 and for .Net 2.
This finally caused the BuildSessionFactory to execute successfully, let me create a session and query a table in the database.
I had feared that ODP would not work using the .Net 4 profile, and had thus switched to .Net 2.0 and .Net 3.5 to debug. However, you don’t have Linq in .Net 2, and the Oracle assembly cannot be referenced by projects targeting .Net 3.5 Client Profile and .Net 4.0 Client Profile. Adding the qualified assembly worked in .Net 4, after all.