Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
内存中的SQLite和NHibernate_Nhibernate_Sqlite_In Memory Database - Fatal编程技术网

内存中的SQLite和NHibernate

内存中的SQLite和NHibernate,nhibernate,sqlite,in-memory-database,Nhibernate,Sqlite,In Memory Database,我在这里有点迷路了 我搜索了一些信息,似乎有几个SQLite GUI工具来创建SQLite DB文件。同时,我还注意到NHibernate附带了SQLite的内存配置 return Fluently.Configure().Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyEntityMap>()).Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).Buil

我在这里有点迷路了

我搜索了一些信息,似乎有几个SQLite GUI工具来创建SQLite DB文件。同时,我还注意到NHibernate附带了SQLite的内存配置

return Fluently.Configure().Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyEntityMap>()).Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory();
我的实体类

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()

我猜您真的需要一个专门用于测试pourpose的内存中数据库。如果是这样,您可以在测试初始化中让NHibernate为您创建模式:

 SchemaExport se = new SchemaExport(cfg);
            se.Create(true, true);

然后您就可以开始添加和使用实体了。

我猜您确实需要一个专门用于测试pourpose的内存中数据库。如果是这样,您可以在测试初始化中让NHibernate为您创建模式:

 SchemaExport se = new SchemaExport(cfg);
            se.Create(true, true);

然后,您可以开始添加和使用实体。

如果您使用的是InMemoryDB,则不会创建PHSYIC文件,并且当SessionFactory被释放时,InMemoryDB将丢失

这使得InMemoryDB非常适合单元测试,因为它不需要一直设置/拆卸

我希望您的目的是为了测试,而不是真正的应用程序:)

要创建所有表,则需要导出配置,如下所示:

return Fluently.Configure()
              .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyEntityMap>())
              .Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory()
              .ExposeConfiguration(x =>
               {
                  new SchemaExport(x).Execute(false, true);
               });
流畅地返回。Configure()
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory()
.ExposeConfiguration(x=>
{
新SchemaExport(x).Execute(false,true);
});

如果您使用的是InMemoryDB,则不会创建PHSYIC文件,并且当处理SessionFactory时,InMemoryDB将丢失

这使得InMemoryDB非常适合单元测试,因为它不需要一直设置/拆卸

我希望您的目的是为了测试,而不是真正的应用程序:)

要创建所有表,则需要导出配置,如下所示:

return Fluently.Configure()
              .Mappings(m => m.FluentMappings.AddFromAssemblyOf<MyEntityMap>())
              .Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory()
              .ExposeConfiguration(x =>
               {
                  new SchemaExport(x).Execute(false, true);
               });
流畅地返回。Configure()
.Mappings(m=>m.FluentMappings.AddFromAssemblyOf())
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql()).BuildSessionFactory()
.ExposeConfiguration(x=>
{
新SchemaExport(x).Execute(false,true);
});

因此,如果我需要将一些数据填充到内存数据库中,我必须使用NH来插入,对吗?@hardywang-是的,这是正确的。但是上面的操作至少会根据映射为您创建所有表。因此,如果我需要将一些数据填充到内存数据库中,我必须使用NH来插入,对吗?@hardywang-是的,这是正确的。但上面的操作至少会根据映射为您创建所有表。我尝试了
SchemaExport.Execute
SchemaExport.create
,但它似乎没有在内存表中创建模式。因为我试图读取或插入be表,并得到“SQLite错误没有这样的表:我的表名”错误。我只是想有一个简单的方法可以检查内存表的状态吗?应该可以。您是如何创建映射的?如何创建cfg?请将其添加到您的问题中。请参阅我上面的问题,我包括了entity类、fluent nhibernate映射类和configurationFor InMemory数据库,您必须在与要执行的查询相同的会话中导出架构。请看,我尝试了
SchemaExport.Execute
SchemaExport.Create
,但它似乎没有在内存表中创建模式。因为我试图读取或插入be表,并得到“SQLite错误没有这样的表:我的表名”错误。我只是想有一个简单的方法可以检查内存表的状态吗?应该可以。您是如何创建映射的?如何创建cfg?请将其添加到您的问题中。请参阅我上面的问题,我包括了entity类、fluent nhibernate映射类和configurationFor InMemory数据库,您必须在与要执行的查询相同的会话中导出架构。看看