ここでは紛失しています。メモリ内SQLiteとNHibernate
私はいくつかの情報を検索しましたが、確かにSQLite DBファイルを作成するいくつかのSQLite GUIツールがあります。一方、私はまた、NHibernateは気づいたDBファイルを使用するオプションはありません、このような設定でSQLiteの
return Fluently.Configure().Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyEntityMap>()).Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory();
のメモリ内のコンフィギュレーションが付属しています。だから、すべてのCRUD操作を実行するためにNHibernateを使用する前に、どのようにすべてのテーブル構造を作成し、レコードをメモリ内のデータベースに挿入するのですか?
編集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()
私はメモリDbにいくつかのデータを設定する必要があるので、私は、挿入するためにNHを使用する必要がありますか? – hardywang
@hardywang - そうです。しかし、上記のことは、少なくともあなたのマッピングに基づいてすべてのテーブルを作成します。 – Phill