sapiens / SqlFu

Fast and versatile .net core data mapper/micro-orm
Other
229 stars 50 forks source link

Using MVC Mini Profiler #15

Closed jchristenson closed 11 years ago

jchristenson commented 11 years ago

Is there any way to wrap the db connection used by SqlFu with a MiniProfiler profiled connection so the results of the queries can be profiled? The only thing I can think of is to write a new class that implements IHaveDbProvider that inherits from one of the current providers and wraps the connection.

Thanks, John

sapiens commented 11 years ago

Well, a connection created with SqlFu is a SqlFuConnection , so I think you can try this

var realCnx=(db as SqlFuConnection).Connection;
//do the wrapping
jchristenson commented 11 years ago

That doesn't work, because the MiniProfiler needs to update the raw DbConnection with a ProfiledDbConnection so that it can monitor the queries. SqlFuConnection.Connection can't be updated

sapiens commented 11 years ago

Then, the only way is to modify the source to set the internal connection inside SqlFuConnection.

jchristenson commented 11 years ago

I can do that, but I would prefer to use the source code as is. That is too bad, I really like what I see so far from SqlFu, but I also really want to have the MiniProfiler working so I can see the results.

sapiens commented 11 years ago

I've modified SqlFuConnection (devel branch, but it will be included in the next release) to accept a DbConnection. So, perhaps this will work for you

var cnn=new SqlConnection(cnxString);

var profilerCnx=new StackExchange.Profiling.Data.ProfiledDbConnection(cnn, MiniProfiler.Current);

var db= new SqlConnection(profilerCnx,DbEngine.SqlServer);
pocheptsov commented 11 years ago

Should the last statement in your example be var db = new SqlFuConnection(profilerCnx, DbEngine.SqlServer);?

sapiens commented 11 years ago

Indeed, you're right.


var cnn=new SqlConnection(cnxString);

var profilerCnx=new StackExchange.Profiling.Data.ProfiledDbConnection(cnn, MiniProfiler.Current);

var db= new SqlFuConnection(profilerCnx,DbEngine.SqlServer);
jchristenson commented 11 years ago

That will work perfect. When will the update make the normal download and nuGet package?

sapiens commented 11 years ago

SqlFu 2.1.0 was released today