I first came across MiniProfiler when I started a new ruby on rails project. It came built in and I found it very useful to see the time requests spend and a breakdown of it. I think it was only visible on development environment.
I found myself asking the question of whether it was available for ASP.NET web application. Turns out, MiniProfiler was written by the folks at stack overflow. And their primary technology stack is .NET. The library supports both full .NET Framework and the new .NET core. Their existing documentation for ASP.NET integration is easy to follow and they even have a samples repository.
One thing that was missing was NuGet package for NHibernate integration. I wanted to log SQL queries that were getting executed by NHibernate ORM library. I saw that there was couple of NuGet packages published by community members. But, they were not actively worked on by the maintainers.
The latest version for MiniProfiler.Mvc5 NuGet package at the time of writing is 4.2.22, which I’ve installed to my Website project. Following the instructions for ASP.NET MVC 5, my Global.asax.cs file looks like below.
I’ve went ahead and did the changes suggested for both the _Layout.cshtml file and Web.config file.
I’ve installed FluentNHibernate(3.1.0) and NHibernate(5.3.10) packages to the project. I have an MSSQL Server and have a table called employees and will query for all employees and render them in my view. I would like to view the SQL that NHibernate produced and the time it took in my mini profiler.
And rendering the list in my index view
Shows me MiniProfiler without any SQL information.
To report SQL statements to MiniProfiler, we can use one of the SQL wrapper classes.
I have then registered the
With these changes, I’ve now SQL statements available in MiniProfiler.
It also works for inserts
I wasn’t expecting the insert to work with the code I’ve added. When working
with an older version of NHibernate library, I had to also implement
IEmbeddedBatcherFactoryProvider.BatcherFactoryClass as done in
Repo accompanying this blog post can be found at my github repository.