我想将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
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
我遇到的问题是在ProfiledDbConnection上执行“获取”。是否可以在使用Dapper时使用ProfiledDbConnection?
答案 0 :(得分:5)
好的捕获,文档已过时,只是更新了它:
使用类似:
return MiniProfiler.Current != null ?
new MvcMiniProfiler.Data.ProfiledDbConnection(cnn, MiniProfiler.Current) :
cnn;
我杀了工厂,因为我希望人们能够继承ProfiledDbConnection并且静态无法虚拟化。