数据库
首页 > 数据库> > 首页> C#>使用System.Data.OracleClient配置流利的NHibernate

首页> C#>使用System.Data.OracleClient配置流利的NHibernate

作者:互联网

我正在尝试通过Fluent Nhibernate使用System.Data.OracleClient代替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& @Rivarolle应该得到全部的功劳.

标签:nhibernate,c,fluent-nhibernate
来源: https://codeday.me/bug/20191030/1969759.html