1

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?

Community
  • 1
  • 1
Chris
  • 12,192
  • 5
  • 21
  • 23

2 Answers2

0

there is nothing wrong with using ProfiledDbConnectionFactory entity framework is designed to support ignorance i generally just use the debugger tools and create a breakpoint to view my generated sql statements as the code first framework provides the sql statement readily there

i would stick to using profiled connections the way you described in your unit testing as opposed to using it in production code as the profiling may be a performance hit you way also want to consider using the sql profiler included in sql server and there is also an sql profiler available as a visual studio extension however i am not sure if it supports code first as of yet

Chris McGrath
  • 1,727
  • 3
  • 19
  • 45
  • Thanks for the tip, but that's not what I was talking about - I'm not looking for a different profiler - I'm looking for a way to make the mvc mini profiler work with my code – Chris Aug 21 '11 at 21:02
0

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

Chris
  • 12,192
  • 5
  • 21
  • 23