2011-04-03 90 views
2

有時我真的開始想知道我的源代碼中發生了什麼: 我試圖使用npgsql 2.0.11.0連接到PostGres 9.0,我確信我已經做了,但現在,我的計劃將引發NotSupportedException異常,因爲它步入了以下內容:C#/ Postgres/FluentNHibernate:配置npgsql拋出NotSupportedException

ISessionFactory sf = Fluently.Configure() 
         .Database(PostgreSQLConfiguration.PostgreSQL82 
         .ConnectionString(c => c 
         .Host("localhost") 
         .Port(5432) 
         .Database("cw") 
         .Username("cw") 
         .Password("mypass"))) 
         .Mappings(x => x.FluentMappings.AddFromAssemblyOf<MyMapping>()) 
         .BuildSessionFactory(); 

堆棧跟蹤是很整齊看:只有一條線路。

at NHibernate.Dialect.Dialect.GetDataBaseSchema(DbConnection connection) in d:\CSharp\NH\nhibernate\src\NHibernate\Dialect\Dialect.cs:Line 718. 

我想這個轉錄到以下幾點:

ISessionFactory sf = Fluently.Configure() 
         .Database(PostgreSQLConfiguration.PostgreSQL82 
         .ConnectionString(c => c.Is("Server=localhost;Port=5432;Database=cw;User Id=cw;Password=myPass;"))) 
         .Mappings(x => x.FluentMappings.AddFromAssemblyOf<CardTemplateMapping>()) 
         .BuildSessionFactory(); 

不過,結果是一樣的。任何人有類似的問題或 - 更好 - 修復?

回答

4

我想我最終會爲最自我回答的問題持有記錄。

它需要將hbm2ddl.keywords屬性設置爲無。現在它像一個魅力。 乾杯!

.Database(PostgreSQLConfiguration.PostgreSQL82 
         .Raw("hbm2ddl.keywords","none")); 
3

看到你已經找到了解決方案。所以只是爲了一些背景:

「none」將禁用任何有關RDBMS關鍵詞的操作。

關鍵字可用於MsSQL,Oracle,Firebird,MsSqlCe,MySQL,SQLite,SybaseAnywhere。

由於Postgress不在列表中,它必須設置爲None。

這裏有這方面的信息:Quoting column names with NHibernate and PostgreSQL

相關問題