2017-08-11 63 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(); 
} 

¿請您給它一個嘗試,看看問題是否解決?

相關問題