开发者

Dapper with MVCMiniProfiler

I am wanting to use the MVCMiniProfiler with Dapper. Is this possible beyond wrapping the "Query" call from dapper in "Using Profiler.Step" block?

I have this basic Dapper call:

Dim comments As List(Of Comment)
Using conn = New SqlConnection(ConnectionString)
conn.Open()
comments = conn.Query(Of Comment)("SELECT * from comments where userid = @userid",       New With {.userid= 1})
End Using

The MiniProfiler examples开发者_如何学Go show this

Private Shared _sqlConnection As SqlConnection
Public Shared Function GetOpenConnection() As DbConnection
    If _sqlConnection Is Nothing Then
            _sqlConnection = New SqlConnection("connection string")
    End If
    ' wrap the connection with a profiling connection that tracks timings 
    Return MvcMiniProfiler.Data.ProfiledDbConnection.[Get](_sqlConnection, MiniProfiler.Current)
End Function

Where I am stuck is in the implementation of the "Get" on the ProfiledDbConnection. Is it possible to use ProfiledDbConnection while using Dapper?


Good catch, the documentation is out of date, just updated it:

Use something like:

return MiniProfiler.Current != null ? 
        new MvcMiniProfiler.Data.ProfiledDbConnection(cnn, MiniProfiler.Current) : 
        cnn;

I killed the factory cause I wanted people to be able to inherit off ProfiledDbConnection and statics can not be virtualized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜