NHibernate App.Config
When you new Configuration().Configure(), app/web.config is easiest (and the first default). If not found, it looks for hibernate.cfg.xml in the current directory, or you must pass in a path or an IDictionary.
- Change the dialect and driver class to fit the database.
- Change the connection string (connection.connection_string_name for the standard connectionStrings section, or connection.connection_string)
- The current_session_context_class will be "thread_static" in test and windows apps, and "web" in asp. Optional depending if you use session context.
- From 2.1 (March 2009), add "proxyfactory.factory_class" with Castle or LinFu (or Spring, coming soon). For Castle, include NHibernate.ByteCode.Castle.dll in deployment (plus Castle.DynamicProxy2.dll and Castle.Core).
- You'll probably want to configure log4net to show more detailed sql (but not everything). See here (add a logger for "NHibernate.SQL" on ALL)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<!-- Change these to Oracle, Sql2000 etc-->
<property name="connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>
<!-- Connection string or connection string name -->
<!--<property name="connection.connection_string">Server=.\SQLEXPRESS;Database=Northwind;Integrated Security=True;</property>-->
<property name="connection.connection_string_name">
Northwind
</property>
<!-- web or thread_static-->
<property name="current_session_context_class">
thread_static
</property>
<!-- Help debugging-->
<property name="show_sql">
true
</property>
<!-- NHibernate 2.1 + -->
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle
</property>
</session-factory>
</hibernate-configuration>
<connectionStrings>
<add name="Northwind" connectionString="Server=.\SQLEXPRESS;Database=Northwind;Integrated Security=True;" providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>