【问题标题】:How to configure the driver when using fluent Nhibernate?使用fluent Nhibernate时如何配置驱动程序?
【发布时间】:2015-09-03 17:43:13
【问题描述】:

我尝试配置会话,但是当我在 dbConfigObject 中指定时,Visual Studio 告诉我无法创建驱动程序。

我在 App.config 中有 Oracle.DataAccess 库和我的连接字符串。 我在 FluentNhibernateHelper 中的代码是这样的:

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();
    }
}

【问题讨论】:

    标签: c# oracle nhibernate fluent-nhibernate nhibernate-configuration


    【解决方案1】:

    没有足够的关于来自 NHibernate 的异常的信息......但万一你得到:

    ...无法从 NHibernate.Driver.OracleDataClientDriver 创建驱动程序...

    因为代码看起来没问题,你应该检查这个问答:

    Fluent NHibernate - Configure Oracle Data Provider ODP

    我想通了。当您引用 ODP 时,您必须将引用的复制本地属性设置为 true,否则它将找不到它正在寻找的对象。

    【讨论】:

      猜你喜欢
      • 2012-06-06
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-14
      • 1970-01-01
      相关资源
      最近更新 更多