tags:

views:

1395

answers:

7

Hi,

I am using linq to Nhibernate to fire some select query to data base.

My question is, how do I know, the query generated by Fluent NHibernate?

+2  A: 

See this. What you need is hibernate.show_sql.

Anton Gogolev
thanks...............
Rahul Somwanshi
How do you configure that with Fluent NHibernate?
Kevin Berridge
+7  A: 

With Fluent NHibernate, you can turn on show_sql like this:

Fluently.Configure().Database( MsSqlConfiguration.MsSql2005.ShowSql().ConnectionString(...) )...

NHibernate will now print every sql statement to Console.Out.

Kevin Berridge
Hi Kevin,Thanks for posting this! I'm wondering if you've also hooked up Log4Net so it sends the generated SQL to a file?
5x1llz
+4  A: 

You might also find this useful http://nhprof.com/

Chris Canal
A: 

You can use sql profilers like this one too.

Arnis L.
A: 

You can also hook in log4net.

Paco
A: 

If you want the SQL to be in log4net, make sure you set the logger in your configuration section.

I put the NHibernate package at "INFO" to reduce the noise and the NHibernate.SQL to all so I can log all SQL statements.

  
 <logger name="NHibernate">
   <level value="INFO" />
 </logger>


  <logger name="NHibernate.SQL">
    <level value="ALL" />
  </logger>

Joey V.
A: 

Definitely buy and use NHProf. This is an awesome product and not only shows you what queries are being run, but also shows you any potential performance problems with your NHibernate mappings and queries.

Deeksy