title: In-Memory SQLite and NHibernate
body: <p>I am kind of lost here.</p>
  
  <p>I searched some information, appearently there are several SQLite GUI tool to create SQLite DB file. Meanwhile I also noticed NHibernate comes with an in-memory configuration of SQLite</p>
  
  <pre><code>return Fluently.Configure().Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;MyEntityMap&gt;()).Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory();
  </code></pre>
  
  <p>With such a setting there is no option to use DB file. So how can I create all table structure and insert records to in-memory database first before I use NHibernate to perform all CRUD operations?</p>
  
  <p>Thanks</p>
  
  <p>Edit 1 -- included mapping class and session class
  My entity base class</p>
  
  <pre><code>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
  </code></pre>
  
  <p>My entity class</p>
  
  <pre><code>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
  </code></pre>
  
  <p>End Class</p>
  
  <p>My mapping class</p>
  
  <pre><code>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
  </code></pre>
  
  <p>And my session configuration</p>
  
  <pre><code>    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()
  </code></pre>