Search code examples
asp.net-mvcentity-framework-4.1ef-code-firstmvc-mini-profiler

no sql profiling for Entity Framework Code First


I've been struggling with this for a while now, and I see that I'm not the only one with the problem (see this and that).

I've managed to debug for a bit, and found a solution, though I'm pretty sure that this is not the 'right' way.

The first debug session (before the dev server was enabled) showed that the ProfiledDbConnectionFactory and ProfiledDbConnection classes provide the required data, but then AFTER the connection is created, the static Instance property on ProfiledDbProviderFactory is initialized (by calling the default constructor) and apparently CreateConnection() is run on that instance resulting with a null reference exception (tail is null).

I've managed to solve this by running

ProfiledDbProviderFactory.Instance.InitProfiledDbProviderFactory(_profiler, ripInnerProvider(_conn));

at the end of ProfiledDbConnection(DbConnection connection, IDbProfiler profiler).

This allows me to view the sql profiling, but as I wrote, I have a feeling that this isn't the correct fix.

Here's the sample code I used. Not sure if there is something wrong with my environment, or my code, as I have a feeling that this should work out of the box. Any comments/suggestions? Sam?


Solution

  • This problem has been resolved in version 1.9.1 of MiniProfiler.EF