使用System.Data.OracleClient配置Fluent NHibernate
本文关键字:Fluent NHibernate 配置 OracleClient System Data 使用 | 更新日期: 2023-09-27 18:21:29
我正在尝试使用System.Data.OracleClient,而不是带有Fluent Nhibernate的Oracle.DataAccess。据我所知,为了实现这一点,我应该将我的驱动程序从OracleDataClientDriver更改为OracleClientDriver。我已经按照下面的方式配置了它,但我得到了一个错误,看起来它仍在尝试使用OracleDataClientDriver。我做错了什么?
FluentConfiguration configuration = Fluently.Configure()
.Database(
OracleDataClientConfiguration.Oracle10
.ConnectionString(x => x.FromConnectionStringWithKey(connString))
.Provider<NHibernate.Connection.DriverConnectionProvider>()
.Driver<NHibernate.Driver.OracleClientDriver>()
)
这是一个错误,它仍在寻找Oracle.DataAccess,我正试图摆脱它。
[NullReferenceException: Object reference not set to an instance of an object.]
NHibernate.Driver.OracleDataClientDriver..ctor() +134
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) +0
System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +113
System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) +232
System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
System.Activator.CreateInstance(Type type) +6
NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type) +58
NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) +194
[HibernateException: Could not create the driver from NHibernate.Driver.OracleDataClientDriver, NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.]
NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) +334
NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings) +233
NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings) +558
NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties) +1328
NHibernate.Cfg.Configuration.BuildSettings() +85
NHibernate.Cfg.Configuration.BuildSessionFactory() +102
FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() +72
使用OracleClientConfiguration和OracleClientDriver而不是OracleDataClientConfiguration和OracleDataClientDriver
FluentConfiguration configuration = Fluently.Configure()
.Database(
OracleClientConfiguration.Oracle10
.ConnectionString(x => x.FromConnectionStringWithKey(connString))
.Provider<NHibernate.Connection.DriverConnectionProvider>()
.Driver<NHibernate.Driver.OracleClientDriver>()
)
问题中的评论解决了我的问题。我发布这个答案是为了其他人的利益,@PapaBurgundy&竞争对手的回答值得充分肯定。