From an ICriteria, is it possible to retrieve a string containing the SQL that NHibernate is planning on executing? I know that is possible to receive a trace, but I was wondering if there is a method that can be called that generates the SQL (for example, so you don't have to actually flush to the database).
Asked
Active
Viewed 443 times
1
-
1"so you don't have to actually flush to the database" this seems to point to an underlying problem. What are you *really* trying to solve? – Mauricio Scheffer Aug 25 '10 at 12:41
-
2possible duplicate of [How to obtain NHibernate generated SQL in code at runtime?](http://stackoverflow.com/questions/3292224/how-to-obtain-nhibernate-generated-sql-in-code-at-runtime) – Mauricio Scheffer Aug 25 '10 at 13:03
-
@Mauricio Scheffer I have a system for generating reports that is primarily run by a database-savvy IT manager. I want to display a copy of the raw SQL so that he can run it directly on the database if he wants. – cbp Aug 25 '10 at 13:53
2 Answers
0
NHibernate Profiler works great for us. there's a trial available at nhprof.com/ edit: NHProf attaches itself on the connection from your machine to the database and captures any SQL passing by, with the number of results and the time spent on fetching processing. NHProf also gives you all sorts of advice that will improve performance.

increddibelly
- 1,221
- 1
- 15
- 25
-
(Zombie thread alert, sorry) Since the answer is to try to use commercial 3rd party software, a name followed by a link is probably appropriate. ;^) – ruffin May 15 '14 at 20:49
0
It's not directly exposed anywhere. Keep in mind the generated SQL is dialect, driver and batcher dependant, so generation of the final SQL occurs late in the pipeline.

Diego Mijelshon
- 52,548
- 16
- 116
- 154