Configuring NHibernate to display executed SQL does what it’s supposed to, but whenever a SQL string needs to be copy-pasted into SQL Server Management Studio, we have to rearrange it dramatically in order to be compatible.
Before I dive into developing my own application that parses and rearranges this into a more ManagementStudio-friendly SQL, I’d like to reassert that this hasn’t been done before – I’d hate to spend time on this and find out later.
Is there a cheap and practicable way of converting the NH-generated prepared statement into something that’s executable straight away?
Thanks in advance
I know you can do this with nhibernate profiler but this is not a free tool. I would also be interested in a free alternative to doing this.
http://nhprof.com/
Edit
Looks like there is a custom appender out there for log4net that will format it such that you can actually run the sql NHibernate spits out. I saw it in the blog listed below:
http://gedgei.wordpress.com/2011/09/03/logging-nhibernate-queries-with-parameters/
Below is the code I have taken from the above blog and modified to work with Guids:
Here is how you would send this output to the console:
NOTE:
It appears this causes some fairly significant performance issues in a production system. I haven’t found a better way to do this yet but for anyone using this beware of these performance issues