Ok, I have it working with LLBLGen v3.5 with SelfServicing and MvcMiniProfiler 2.0.2.0. This is what you have to do:
- Create a custom DynamicQueryEngine in your DAL generated project:
using System.Data.Common;
using SD.LLBLGen.Pro.DQE.SqlServer;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;
namespace [YourRootNamespace]
{
public class DynamicQueryEngineProfiled : DynamicQueryEngine
{
protected override DbCommand CreateCommand()
{
DbCommand cmd = base.CreateCommand();
return new ProfiledDbCommand(cmd, null, MiniProfiler.Current);
}
}
}
- Create a partial class file for CommonDaoBase and write this:
using SD.LLBLGen.Pro.ORMSupportClasses;
using StackExchange.Profiling;
using StackExchange.Profiling.Data;
namespace [YourRootNamespace].DaoClasses
{
public partial class CommonDaoBase
{
public override System.Data.Common.DbConnection DetermineConnectionToUse(ITransaction containingTransaction)
{
var cnn = base.DetermineConnectionToUse(containingTransaction);
return new ProfiledDbConnection(cnn, MiniProfiler.Current);
}
}
}
- Now you have to tell CommonDaoBase to use your custom DQE. This is the easiest way: open CommonDaoBase.cs and change the constructor to this:
public CommonDaoBase(InheritanceHierarchyType typeOfInheritance, string entityName, IEntityFactory entityFactory)
: base(InheritanceInfoProviderSingleton.GetInstance(), new DynamicQueryEngineProfiled(), typeOfInheritance, entityName, entityFactory)
{
}
That's it, now use MiniProfiler as mentioned in the docs (http://miniprofiler.com). Example:
public ActionResult List()
{
var profiler = MiniProfiler.Current;
using (profiler.Step("Fetching customers..."))
{
var customers = new CustomerCollection();
customers.GetMulti(null);
ViewData.Model = customers.ToList();
}
return View();
}
Make sure to start/stop the profiler, and that the handler is added to your config:
global.asax
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}
protected void Application_EndRequest()
{
MiniProfiler.Stop();
}
web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="false"/>
<handlers>
<add name="MiniProfiler" path="mini-profiler-resources/*" verb="*" type="System.Web.Routing.UrlRoutingModule" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
Note that at Step 3 there is a little problem: when you regenerate code that will be overwritten. To overcome that, you could change the template for CommonDaoBase so the custom DQE is emitted always in the constructor. You can write your own version of the template/binding and then move it up in the template bindings precedence at the Generate Code wizard. This is explained in the SDK docs.
Hope helpful