Thursday, March 24, 2011

NHibernate FAQ: How to configurate NHibernate to work with PostgreSQL

1. Download SQL driver Npgsql (in time of writing the most reason version was 2.0.11) here...
Note: pick right version of Npgsql the one that suits your version of .Net runtime.

2. Add Npgsql.dll as references to you project.

3. Then add the following lines to your NHibernate configuration file:
<property name="connection.driver_class">NHibernate.Driver.NpgsqlDriver</property>
<property name="connection.connection_string">
 Server=localhost;Database=dbname;User ID=username;Password=yourpassword;
<property name="dialect">NHibernate.Dialect.PostgreSQLDialect</property> 

That's all. Happy hibernating with PostgreSQL :)