2010-09-19 96 views
1

通过查看StackOverflow这个问题似乎被问了很多,但我已经尝试了所有列出的,似乎无法让他们任何工作。NHibernate与Windows应用程序

我目前正尝试在.NET 4.0中用C#编写的Windows应用程序中使用NHibernate。我目前的平台目标是x86,并且我已确认我正在使用x86 System.Data.SQLite,并且已将其设置为在本地复制。我目前的操作系统是Windows 7 x64。

我也有一个大会,是使用NHibernate和谈判与数据库中的一个,它是当我尝试打电话到它,我得到以下错误:

************** Exception Text ************** 
NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.SQLite20Driver. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> NHibernate.HibernateException: The IDbCommand and IDbConnection implementation in the assembly System.Data.SQLite could not be found. Ensure that the assembly System.Data.SQLite is located in the application directory or in the Global Assembly Cache. If the assembly is in the GAC, use <qualifyAssembly/> element in the application configuration file to specify the full name of the assembly. 
    at NHibernate.Driver.ReflectionBasedDriver..ctor(String driverAssemblyName, String connectionTypeName, String commandTypeName) 
    at NHibernate.Driver.SQLite20Driver..ctor() 
    --- End of inner exception stack trace --- 
    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 NHibernate.Bytecode.ActivatorObjectsFactory.CreateInstance(Type type) 
    at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) 
    --- End of inner exception stack trace --- 
    at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary`2 settings) 
    at NHibernate.Connection.ConnectionProvider.Configure(IDictionary`2 settings) 
    at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary`2 settings) 
    at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary`2 properties) 
    at NHibernate.Cfg.Configuration.BuildSettings() 
    at NHibernate.Cfg.Configuration.BuildSessionFactory() 
    at Surrix.Cerberus.YouthData.Respositories.NHibernateHelper.get_SessionFactory() in D:\development\Cerberus\YouthData\Respositories\NHibernateHelper.cs:line 20 
    at Surrix.Cerberus.YouthData.Respositories.NHibernateHelper.OpenSession() in D:\development\Cerberus\YouthData\Respositories\NHibernateHelper.cs:line 29 
    at Surrix.Cerberus.YouthData.Respositories.YouthRepository.GetYouthByLastName(String lastName) in D:\development\Cerberus\YouthData\Respositories\YouthRepository.cs:line 41 
    at Surrix.Cerberus.YouthCheckinUI.YouthCheckinMainForm.searchButton_Click(Object sender, EventArgs e) in D:\development\Cerberus\YouthCheckinUI\YouthCheckinMainForm.cs:line 31 
    at System.Windows.Forms.Control.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnClick(EventArgs e) 
    at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) 
    at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.ButtonBase.WndProc(Message& m) 
    at System.Windows.Forms.Button.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

我不能似乎弄清楚在这里要做什么。如果有人遇到过此问题,请协助。

下面是我的Hibernate Config文件。

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory> 
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> 
    <property name="connection.connection_string"> 
     Data Source=D:\\development\\cerberus\\test.s3db;Version=3 
    </property> 
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
    <property name="query.substitutions">true=1;false=0</property> 
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> 

    <property name="show_sql">true</property> 
    </session-factory> 
</hibernate-configuration> 
+1

我很同意,软件工程正在成为一个黑匣子魔法,你需要知道的“食谱”,并不再软件工程原则:(。这些框架通常并不能解释所有的插件和配置出局,似乎他们想让大师们为他们的推广编写和出售书籍:) – user310291 2010-09-19 07:58:39

回答

0

我不知道为什么这个工程在NUnit测试,而不是在一个WPF应用程序,但添加:这再次单元测试,但使用时不是当它下一个Windows应用程序的工作原理

useLegacyV2RuntimeActivationPolicy="true" 

到你的启动标签在app.config中解决了我的问题。我的app.config现在看起来像:

<?xml version="1.0"?> 
<configuration> 
    <startup useLegacyV2RuntimeActivationPolicy="true">  
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 
</configuration> 
2

检查该SO文章,看起来像它与引用组件的特定目标的问题。

SQL.Data.SqlLite version with NHibernate 2.1

+0

本文是一篇很好的阅读,并且我已经完成了文章中列出的一些内容,但是我的回答是真正解决了我的问题。 – 2010-09-20 19:25:11

相关问题