2012-03-31 3 views
1

Я новичок в NHibernate поэтому, пожалуйста, идти легко на меня, если я задал глупый вопрос ...NHibernate Учебник Run-Time Error: 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

+0

Привет, серфин, я просто попытался добавить ссылку на тестовый проект и получить тот же результат. Я тестирую машину x64. – Kashif

+0

Я забыл установить для свойства «Копировать локальное» значение true в ссылке в тестовом проекте. Он больше не падает на этой линии. Мне нужно будет увидеть, работает ли это на самом деле. Спасибо! – Kashif

ответ

2

Скопировано в ответ от комментариев, так как он оказывается так:

Убедитесь, что вы добавить ссылку на System.Data.SqlServerCe и установить CopyLocal=true на как основной проект и тестовый проект.