【问题标题】:Dapper with MVCMiniProfiler使用 MVCMiniProfiler 的 Dapper
【发布时间】:2011-09-08 09:03:10
【问题描述】:

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

我有这个基本的 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 上执行“Get”。使用 Dapper 时是否可以使用 ProfiledDbConnection?

【问题讨论】:

    标签: mvc-mini-profiler dapper


    【解决方案1】:

    很好,文档已过时,刚刚更新:

    使用类似的东西:

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

    我杀死了工厂,因为我希望人们能够继承 ProfiledDbConnection 并且静态不能被虚拟化。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-10
      • 2012-08-18
      相关资源
      最近更新 更多