C# Fluent SQLLite InMemory System.Data.SQLite.SQLiteException : SQL 逻辑错误或缺少数据库 "(" : 语法错误


public void Initialize()
{
sessionFactory = CreateSessionFactory();
}
private ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TestMetaData>())
.ExposeConfiguration(cfg => configuration = cfg)
.BuildSessionFactory();
}
public ISession OpenSession()
{
ISession session = sessionFactory.OpenSession();
var export = new SchemaExport(configuration);
export.Execute(true, true, false, session.Connection, null);
return session;
}

这部分正在生成错误System.Data.SQLite.SQLiteException : SQL 逻辑错误或缺少靠近"("的数据库:语法错误

有什么想法吗?

我认为问题在于您何时在公开的配置上应用架构导出。您应该在构建会话工厂之前执行此操作。

创建了您正在设置它的分离方法OpenSession((后,我怀疑您错误地应用了它。

因此,您的会话工厂创建应该是这样的

private ISessionFactory CreateSessionFactory()
{
//the session in which you might want to export your schema
ISession session = sessionFactory.OpenSession();
return Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<TestMetaData>())
.ExposeConfiguration(cfg =>
{
//we set the configuration here, and execute it, 
//before the session factory is built.
var export = new SchemaExport(cfg);
export.Execute(true, true, false, session.Connection, null);
})
.BuildSessionFactory();
}

¿您能否尝试一下并检查问题是否已解决?

最新更新