Tip of the day for NHibernate #2: show_sql and format_sql

Wednesday, January 19, 2011

As always with tips, either you already know this or it would be invaluable. This time I'm talking about 2 configuration properties: "show_sql" and "format_sql". To switch on these options, add the corresponding lines to your hibernate.cfg.xml file as in the following example: <?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">   <session-factory>     <property name="connection.connection_string">Data Source=.;Initial Catalog=NHibernateDemo;Integrated Security=True</property>     <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>     <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>     <property name="show_sql">True</property>     <property name="format_sql">True</property>     <mapping assembly="BusinessLogic"/>   </session-factory> </hibernate-configuration> What is does? The “show_sql” property tells NHibernate to output all the SQL statements it executes onto the console. This way you can see exactly what...