C# / Postgres / FluentNHibernate : configuring npgsql throws NotSupportedException

僤鯓⒐⒋嵵緔 提交于 2019-12-01 23:58:31

问题


Sometimes I really start wondering what's going on in my sourcecode: I'm trying to connect to PostGres 9.0 using npgsql 2.0.11.0, which I'm damn sure I already did, but right now, my program throws a NotSupportedException as it steps into the following :

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

The Stacktrace is quite neat to look at: Just one line.

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

I tried transcribing this to the following:

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

Still, the result's the same. Anybody had similar issues or - even better - a fix?


回答1:


I guess I'll end up holding a record for the most self-answered questions.

It needed the hbm2ddl.keywords property set to none. Now it works like a charm. Cheers!

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



回答2:


See that you already found a solution. So just for some background:

The "none" will disable any operation regarding RDBMS KeyWords.

And the Keywords is available for MsSQL, Oracle, Firebird, MsSqlCe, MySQL, SQLite, SybaseAnywhere.

Since Postgress is not in the list it has to be set to None.

There is som info on it here: Quoting column names with NHibernate and PostgreSQL



来源:https://stackoverflow.com/questions/5532236/c-sharp-postgres-fluentnhibernate-configuring-npgsql-throws-notsupportedex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!