我有点迷失在这里。
我搜索了一些信息,似乎有几个 SQLite GUI 工具可以创建 SQLite DB 文件。同时我还注意到 NHibernate 带有 SQLite 的内存配置
return Fluently.Configure().Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyEntityMap>()).Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory();
有了这样的设置,就没有使用 DB 文件的选项了。那么,在使用 NHibernate 执行所有 CRUD 操作之前,如何先创建所有表结构并将记录插入内存数据库?
谢谢
编辑1——包括映射类和会话类我的实体基类
Public MustInherit Class SingleKeyEntity(Of TId)
Public Overridable Property Id() As TId
Get
Return m_Id
End Get
Set(value As TId)
m_Id = value
End Set
End Property
End Class
我的实体类
Public Class Subscription
Inherits SingleKeyEntity(Of System.Nullable(Of Integer))
Private m_Subscriber As String
Public Overridable Property Subscriber() As String
Get
Return m_Subscriber
End Get
Set(value As String)
m_Subscriber = value
End Set
End Property
Private m_Format As String
Public Overridable Property Format() As String
Get
Return m_Format
End Get
Set(value As String)
m_Format = value
End Set
End Property
结束类
我的地图课
Public Class SubscriptionMap
Inherits ClassMap(Of Subscription)
Public Sub New()
Table("SUBSCRIPTIONS")
Id(Function(x) x.Id, "ID").GeneratedBy.Identity()
Map(Function(x) x.Subscriber, "SUBSCRIBER").[Not].Nullable()
Map(Function(x) x.Format, "DISTRIBUTION_FORMAT").[Not].Nullable()
' more properties omitted
End Sub
End Class
还有我的会话配置
Return Fluently.Configure() _
.Mappings(Function(m) m.FluentMappings.AddFromAssemblyOf(Of SubscriptionMap)()) _
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql()) _
.ExposeConfiguration(Sub(x As NHibernate.Cfg.Configuration)
Dim export As SchemaExport = New SchemaExport(x)
'export.Execute(False, True, False)
export.Create(False, True)
End Sub) _
.BuildSessionFactory()