How to configure the driver when using fluent Nhibernate?

1.3k Views Asked by At

I tried to configure the session but the visual studios tell me could not create a driver when I specified in the dbConfigObject.

I have the Oracle.DataAccess library and my connetion string in App.config. My code in FluentNhibernateHelper is like this:

public static class FluentNHibernateHelper
{
    private static ISessionFactory _sessionFactory;
    public static ISessionFactory SessionFactory
    {
        get
        {
            if (_sessionFactory == null)
            {
                var dbConfig = OracleDataClientConfiguration.Oracle10
                .ConnectionString(c => c.FromConnectionStringWithKey("Oracle"))
                .Driver<OracleDataClientDriver>()
                .ShowSql();
                _sessionFactory = Fluently.Configure()
                  .Database(dbConfig)
                  .Mappings(m => m.FluentMappings.AddFromAssemblyOf<Empleado>())
                  .BuildSessionFactory();
            }
            return _sessionFactory;
        }
    }

    public static ISession OpenSession()
    {
        return SessionFactory.OpenSession();
    }
}
1

There are 1 best solutions below

0
On

There is not enough information about the exception coming from NHibernate... but in case you get:

...Could not create the driver from NHibernate.Driver.OracleDataClientDriver...

and because the code seems to be ok, you should check this Q & A:

Fluent NHibernate - Configure Oracle Data Provider ODP

I figured it out. When you reference the ODP you have to set the the copy local property of the reference to true otherwise it won't find the objects it is looking for.