我在设置 SQLite inMemory 数据库时遇到问题,我已经从这里http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki安装了 sqlite
我收到了这个 Nhibernate 异常
SQL逻辑错误或缺少数据库,未知数据库核心
尝试运行单元测试时,在 BuildSchema 方法中引发异常
这是我的工厂代码
Imports NHibernate.Tool.hbm2ddl
Namespace SessionManager
Public Class Factory
Private Sub New()
End Sub
Private Shared _configuration As NHibernate.Cfg.Configuration
Private Shared _sessionFactory As NHibernate.ISessionFactory
Public Shared Function OpenTestSession() As NHibernate.ISession
If SessionFactory Is Nothing Then
SessionFactory = CreateSessionFactory()
Dim sx = SessionFactory.OpenSession()
'BuildSchema2(sx)
Return sx
End If
End Function
Private Shared Function CreateSessionFactory() As NHibernate.ISessionFactory
Return FluentNHibernate.Cfg.Fluently.Configure().Database(GetInMemoryDataBaseConfiguration()).Mappings(Sub(m) m.FluentMappings.AddFromAssemblyOf(Of ModelEntity)()).ExposeConfiguration(Sub(Cfg) BuildSchema3(Cfg)).BuildSessionFactory()
End Function
Private Shared Function CreateSessionFactory2() As NHibernate.ISessionFactory
Return FluentNHibernate.Cfg.Fluently.Configure().Database(GetInMemoryDataBaseConfiguration()).Mappings(Sub(m) m.FluentMappings.AddFromAssemblyOf(Of ModelEntity)()).ExposeConfiguration(Function(Cfg) InlineAssignHelper(_configuration, Cfg)).BuildSessionFactory()
End Function
Private Shared Sub BuildSchema(config As NHibernate.Cfg.Configuration)
Dim se = New SchemaExport(config)
se.Create(False, True)
End Sub
Private Shared Sub BuildSchema2(sx As NHibernate.ISession)
Dim se = New SchemaExport(_configuration)
se.Execute(True, True, False, sx.Connection, Nothing)
End Sub
Private Shared Sub BuildSchema3(config As NHibernate.Cfg.Configuration)
Dim se = New SchemaExport(config)
se.Create(True, True)
End Sub
Private Shared Function GetInMemoryDataBaseConfiguration() As FluentNHibernate.Cfg.Db.SQLiteConfiguration
Return FluentNHibernate.Cfg.Db.SQLiteConfiguration.Standard.InMemory()
End Function
Private Shared Function InlineAssignHelper(Of T)(target As T, value As T) As T
target = value
Return value
End Function
End Class
结束命名空间
如果有人知道解决方案或指出我的解决方案,我将赠送积分:)
编辑
SQLite 似乎与我们的 SQL Server 架构存在问题,当我映射没有架构的表时,它可以工作......关于如何获取映射以忽略表映射中的架构的任何想法:)。
除此之外,我还发现了与此相关的问题... Fluent NHibernate - Remove Schema from Mappings for Testing with SQLite