我有點迷失在這裏。內存中的SQLite和NHibernate
我搜索了一些信息,顯然有幾個SQLite GUI工具來創建SQLite數據庫文件。同時我也注意到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()
因此,如果我需要填充一些數據到內存中,我將不得不使用NH來插入,對吧? – hardywang 2011-12-23 14:31:44
@hardywang - 是的,這是正確的。但上面的內容至少會根據你的映射爲你創建所有的表格。 – Phill 2011-12-23 14:40:17