我試圖使用SQLite和NHibernate的第一次測試我的映射,但是我得到這個錯誤:NHibernate的/ FluentNHibernate和SQLite在內存映射測試
Test method BMGChip.Tests.clsCorrespondenteMapTest.Can_correctly_map_Correspondente threw exception:
NHibernate.Exceptions.GenericADOException: could not insert: [BMGChip.NHibernate.Entities.clsCorrespondente][SQL: INSERT INTO CPHSITE12_COR (COR_NOM, COR_EMA, COR_TEL, COR_RUA, COR_NUM, COR_COM, COR_CID, COR_EST, COR_CEP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?); select last_insert_rowid()] ---> System.Data.SQLite.SQLiteException: SQLite error
no such table: CPHSITE12_COR
我試圖創建併爲每個測試方法刪除數據庫。
我的NHibernate的配置:
Public Class clsSessionFactoryBuilder
Private Shared _sessionFactory As ISessionFactory
Private Shared Function GetSessionFactory() As ISessionFactory
If _sessionFactory Is Nothing Then
_sessionFactory = Fluently.Configure() _
.Mappings(Function(m) m.FluentMappings.AddFromAssemblyOf(Of clsFaleConoscoMap)()) _
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql()) _
.ExposeConfiguration(Function(cfg) ExportarSchema(cfg)) _
.ExposeConfiguration(Function(cfg) cfg.SetProperty("current_session_context_class", "thread_static")) _
.BuildSessionFactory()
End If
Return _sessionFactory
End Function
Public Shared Sub OpenSession()
Dim session As ISession = GetSessionFactory.OpenSession
CurrentSessionContext.Bind(session)
End Sub
Public Shared Function GetCurrentSession() As ISession
Return GetSessionFactory.GetCurrentSession
End Function
Public Shared Sub CloseSession()
Dim session As ISession = CurrentSessionContext.Unbind(_sessionFactory)
If session Is Nothing Then Return
Try
'session.Transaction.Commit()
Catch ex As Exception
'session.Transaction.Rollback()
Finally
session.Close()
session.Dispose()
End Try
End Sub
Private Shared Function ExportarSchema(ByVal configuration As Cfg.Configuration)
Dim export As New SchemaExport(configuration)
export.Create(False, True)
Return Nothing
End Function
End Class
我的測試:
<TestMethod()>
Public Sub Can_correctly_map_Correspondente()
clsSessionFactoryBuilder.OpenSession()
Dim session As ISession = clsSessionFactoryBuilder.GetCurrentSession()
With New PersistenceSpecification(Of clsCorrespondente)(session)
.CheckProperty(Function(c) c.Nome, "Fernanda Moreira")
.CheckProperty(Function(c) c.Email, "[email protected]")
.CheckProperty(Function(c) c.Telefone, "(31) 3131-3131")
.CheckProperty(Function(c) c.Rua, "R. Andaluzita")
.CheckProperty(Function(c) c.Numero, "775")
.CheckProperty(Function(c) c.Complemento, "Do lado do Pátio Savassi")
.CheckProperty(Function(c) c.Cidade, "Belo Horizonte")
.CheckProperty(Function(c) c.Estado, "MG")
.CheckProperty(Function(c) c.Cep, "44444-444")
.VerifyTheMappings()
End With
clsSessionFactoryBuilder.CloseSession()
End Sub
可能是什麼?
不要在最後一個參數 – 2012-03-14 17:16:20
使用接受NULL後建立我的模式'Console.Out' – 2012-03-14 18:25:16
不起作用:「FluentNHibernate.Cfg.FluentConfigurationException:一個在創建SessionFactory時使用了無效或不完整的配置。請參閱PotentialReasons集合和InnerException以獲取更多詳細信息。「 – 2012-03-15 12:42:27