2012-03-31 38 views
1

我在NHibernate的一個新手,所以請去容易對我,如果我問一個愚蠢的問題...NHibernate的教程運行時錯誤:HibernateException的

我下面的NHibernate的教程貼here和我得到類型的運行時錯誤「HibernateException的」

有問題的代碼如下所示:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using FirstSolution; 
using NHibernate.Cfg; 
using NHibernate.Tool.hbm2ddl; 
using NUnit.Framework; 

namespace FirstSolution.Tests 
{ 
    [TestFixture] 
    public class GenerateSchema_Fixture 
    { 
     [Test] 
     public void Can_generate_schema() 
     { 
      var cfg = new Configuration(); 
      cfg.Configure(); 
      cfg.AddAssembly(typeof(Product).Assembly); 

      new SchemaExport(cfg).Execute(false, true, false); 
     } 
    } 
} 

我在收到錯誤的線路是:

cfg.AddAssembly(typeof(Product).Assembly); 

最內層的例外是:

The IDbCommand and IDbConnection implementation in the assembly System.Data.SqlServerCe could not be found 

這是我的堆棧跟蹤:

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.Tool.hbm2ddl.SchemaExport.Execute(Action`1 scriptAction, Boolean export, Boolean justDrop) 
    at NHibernate.Tool.hbm2ddl.SchemaExport.Execute(Boolean script, Boolean export, Boolean justDrop) 
    at FirstSolution.Tests.GenerateSchema_Fixture.Can_generate_schema() in C:\Users\Kash\Documents\Visual Studio 2010\Projects\FirstSolution\FirstSolution\GenerateSchema_Fixture.cs:line 23 
    at HibernateUnitTest.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\Kash\Documents\Visual Studio 2010\Projects\FirstSolution\HibernateUnitTest\Form1.cs:line 23 
    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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
    at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) 
    at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData) 
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) 
    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) 
    at System.Windows.Forms.Application.Run(Form mainForm) 
    at HibernateUnitTest.Program.Main() in C:\Users\Kash\Documents\Visual Studio 2010\Projects\FirstSolution\HibernateUnitTest\Program.cs:line 18 
    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() 

我確信,System.Data.SqlServerCe已被引用,並且其Copy Local屬性設置爲True。但是,錯誤依然存在。您的幫助將不勝感激。謝謝。

+2

您是否將對System.Data.SqlServerCe的引用添加到主項目和測試項目中?您是在x86還是x64機器上測試? – surfen 2012-03-31 23:03:20

+0

嗨surfen,我只是嘗試添加對測試項目的引用,仍然得到相同的結果。我正在一臺x64機器上測試。 – Kashif 2012-03-31 23:23:46

+0

我忘了在測試項目的引用中將'Copy Local'屬性設置爲true。它不再在這條線上崩潰。我將不得不看看它是否真的有效。謝謝! – Kashif 2012-03-31 23:30:42

回答

2

複製爲回答評論,因爲它原來是如此:

確保將引用添加到System.Data.SqlServerCe和主體工程和測試項目設置CopyLocal=true

相關問題