配有MVCMiniProfiler的小巧玲珑

eri*_*cdc 6 dapper mvc-mini-profiler

我想将MVCMiniProfiler与Dapper一起使用.除了在"使用Profiler.Step"块中包装来自dapper的"查询"调用之外,这是否可能?

我有这个基本的Dapper电话:

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
Run Code Online (Sandbox Code Playgroud)

MiniProfiler示例显示了这一点

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
Run Code Online (Sandbox Code Playgroud)

我陷入困境的是在ProfiledDbConnection上执行"Get".使用Dapper时是否可以使用ProfiledDbConnection?

Sam*_*ron 5

好的捕获,文档已过时,只是更新它:

使用类似的东西:

return MiniProfiler.Current != null ? 
        new MvcMiniProfiler.Data.ProfiledDbConnection(cnn, MiniProfiler.Current) : 
        cnn;
Run Code Online (Sandbox Code Playgroud)

我杀了工厂因为我希望人们能够继承ProfiledDbConnection并且静态无法虚拟化.