2017-08-11 110 views
1
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逻辑错误或丢失数据库近“(”:语法错误C#流利SQLLite InMemory System.Data.SQLite.SQLiteException:SQL逻辑错误或丢失的数据库接近 “(”:语法错误

任何想法

回答

0

我认为问题的关键在于,当你运用你的模式的出口上的暴露配置在你建立你的会话工厂之前,您应该这样做。 。

创建了重新编写的方法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(); 
} 

¿请您给它一个尝试,看看问题是否解决?

相关问题