MvcMiniProfiler and NHibernate: Take 3
[UPDATE see comments below - avoid this for time being ... batches were working but were not profiling, apologies ...]
[UPDATE 2 - my clone on google code has been updated and batched commands are now profiling (see comments)]
Time for a another NHibernate/MvcMiniProfiler update ...
Although the RealProxy solution for getting the MiniProfiler to work with NHibernate batching and SqlServer showed initial promise, people were still running into problems casting the transparent proxy.
Some people have had success by modifying and recompiling the NHibernate source, but this wasn't something I wanted to do. Others had been duplicating some code from NHibernate in their projects - the cleanest solution I've seen so far was the one that Harry McIntyre describes here -
http://www.adverseconditionals.com/2011/08/fixing-miniprofiler-with-nhibernat...
(Thanks to Harry and "Nick" that his fix was based on)
It duplicates the SqlClientBatchingBatcher from the NHibernate source - with a simple modification that should be easy to keep up-to-date with future NHibernate releases.
This solution also allows us to drop RealProxy and revert to the original wrapping ProfiledDbCommand however I chose to derive a new ProfiledSqlCommand that exposes the wrapped DbCommand, which means we don't need to clone the command and parameters.
For reference my change to SqlClientBatchingBatcher was in "AddToBatch", changing this line -
currentBatch.Append((System.Data.SqlClient.SqlCommand) batchUpdate);
to
if (batchUpdate is ProfiledSqlCommand)
{
currentBatch.Append(((ProfiledSqlCommand)batchUpdate).SqlCommand);
}
else
{
currentBatch.Append((System.Data.SqlClient.SqlCommand)batchUpdate);
}I've cloned the mvc-mini-profiler on Google Code and added a new MvcMiniProfiler.NHibernate project - you can see my current version here -
Would love to hear how other people get on with this, maybe it could be the starting point for an MvcMiniProfiler.NHibernate nuget package?


