Fluent NHibernate - 配置 Oracle Data Provider ODP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3266775/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fluent NHibernate - Configure Oracle Data Provider ODP
提问by Paul Speranza
I am brand new to NHibernate and Fluent NHibernate and I am trying to get the following confguration to work.
我是 NHibernate 和 Fluent NHibernate 的新手,我正在尝试使以下配置工作。
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(
OracleDataClientConfiguration.Oracle10.ConnectionString("Data Source=mysource;User ID=myid;Password=mypwd;")
)
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<Program>())
.BuildSessionFactory();
}
I have the Oracle.DataAccess assembly referenced. I am using VS 2010 and .Net 4
我引用了 Oracle.DataAccess 程序集。我正在使用 VS 2010 和 .Net 4
I get the following exception :
我收到以下异常:
FluentNHibernate.Cfg.FluentConfigurationException was unhandled Message=An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
FluentNHibernate.Cfg.FluentConfigurationException 未处理 Message=创建 SessionFactory 时使用了无效或不完整的配置。检查 PotentialReasons 集合和 InnerException 以获取更多详细信息。
Source=FluentNHibernate
StackTrace:
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 98
at HibernateLearning.Program.CreateSessionFactory() in C:\Projects\CPS Test Concepts\Main\Source\CPSTestConcepts\Source\HibernateLearning\Program.cs:line 48
at HibernateLearning.Program.Main(String[] args) in C:\Projects\CPS Test Concepts\Main\Source\CPSTestConcepts\Source\HibernateLearning\Program.cs:line 21
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: NHibernate.HibernateException
Message=Could not create the driver from NHibernate.Driver.OracleDataClientDriver, NHibernate, Version=2.1.2.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
Source=NHibernate
StackTrace:
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary2 settings)
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary
2 settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary
2 properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 93
InnerException: System.Reflection.TargetInvocationException
Message=Exception has been thrown by the target of an invocation.
Source=mscorlib
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type)
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings)
InnerException: NHibernate.HibernateException
Message=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 element in the application configuration file to specify the full name of the assembly.
Source=NHibernate
StackTrace:
at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName)
at NHibernate.Driver.OracleDataClientDriver..ctor()
InnerException:
ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper .ThreadStart() InnerException: NHibernate.HibernateException Message=无法从 NHibernate.Driver.OracleDataClientDriver、NHibernate、Version=2.1.2.4000、Culture=neutral、PublicKeyToken=aa95f207798dfdb4 创建驱动程序。Source=NHibernate StackTrace: 在 NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: NHibernate.HibernateException Message=无法从 NHibernate.Driver.OracleDataClientDriver 创建驱动程序, NHibernate,版本=2.1.2.4000,文化=中性,PublicKeyToken=aa95f207798dfdb4。Source=NHibernate StackTrace: 在 NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary Boolean ignoreSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart() InnerException: NHibernate.HibernateException Message=无法从 NHibernate.Driver.OracleDataClientDriver 创建驱动程序, NHibernate,版本=2.1.2.4000,文化=中性,PublicKeyToken=aa95f207798dfdb4。Source=NHibernate StackTrace: 在 NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary 版本=2.1.2.4000,文化=中性,PublicKeyToken=aa95f207798dfdb4。Source=NHibernate StackTrace: 在 NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary 版本=2.1.2.4000,文化=中性,PublicKeyToken=aa95f207798dfdb4。Source=NHibernate StackTrace: 在 NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary2 settings)
at NHibernate.Connection.ConnectionProvider.Configure(IDictionary
2 个设置)在 NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary)2 settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary
2 个属性)在 NHibernate.Cfg.Configuration.BuildSettings() 在 NHibernate.Cfg.Configuration.BuildSessionFactory() 在 FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() 在 d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs :line 93 InnerException: System.Reflection.TargetInvocationException Message=调用的目标已抛出异常。Source=mscorlib StackTrace:在 System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) 在 System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache) 在 System. RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache) at System.Activator.CreateInstance(Type type, Boolean nonPublic) at System.Activator.CreateInstance(Type type) at NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type) ) 在 NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) InnerException: NHibernate.HibernateException Message=无法找到程序集 Oracle.DataAccess 中的 IDbCommand 和 IDbConnection 实现。确保程序集 Oracle.DataAccess 位于应用程序目录或全局程序集缓存中。如果程序集在 GAC 中,使用应用程序配置文件中的元素来指定程序集的全名。源 = NHibernate StackTrace: 在 NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName) at NHibernate.Driver.OracleDataClientDriver..ctor() InnerException:
回答by Paul Speranza
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.
我想到了。当您引用 ODP 时,您必须将引用的复制本地属性设置为 true,否则它将找不到它正在寻找的对象。
One hurdle down, I'm sure there will be more but I am loving these tools!
一个障碍,我相信会有更多,但我喜欢这些工具!
Paul
保罗
回答by Peter Walke
You might also get this problem if you have a mismatch between the platforms of the ODP dll and the platform of your application (x86 vs x64). Change your project to compile against the correct platform.
如果 ODP dll 的平台与应用程序的平台(x86 与 x64)不匹配,您也可能会遇到此问题。更改您的项目以针对正确的平台进行编译。