Dapper with MVCMiniProfiler

I want to use MVCMiniProfiler with Dapper. Is this possible after completing the "Query" call from the dapper in the "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 

MiniProfiler examples 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 with the implementation of "Get" on ProfiledDbConnection. Can I use ProfiledDbConnection when using Dapper?

+6
source share
1 answer

Good trick, 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 because I wanted people to be able to inherit ProfiledDbConnection, and statics could not be virtualized.

+5
source

Source: https://habr.com/ru/post/896804/


All Articles