Is there any way to get the query text - i.e. plain SQL - of an NHibernate query from a DetachedCriteria object (or any NHibernate object, I just want to be pointed in the right direction) BEFORE it is sent to my server? If so, can I prevent it from executing?
A:
I don't know if there is an easy way of doing this. There might be a listener you can use to display the sql and then abort the execution. I've never used one for this purpose.
If you simply want to debug your queries and don't want to hit your database then write some tests using an in-memory database. In my opinion this is a much better strategy.
You can observe the queries that are being generated by tailing your log files or using NHProf.
Nigel
2009-07-03 14:09:10