Mini profiler with Simple.Data

Can I use Mini-Profiler with Simple.Data Library? I use it to get data from MySql as follows:

var db = Database.OpenConnection(ConnectionString); var book = db.Books.FindById(id); 

How can I profile a user with this code?

+4
source share
2 answers

You can tell Simple.Data to use pre-existing connections and wrap the connection with a profiled connection:

 var db = Database.OpenConnection(ConnectionString); using (var rawCnn = new MySqlConnection(ConnectionString)) using (var profiledCnn = new MvcMiniProfiler.Data.ProfiledDbConnection(rawCnn, MiniProfiler.Current); { profiledCnn.Open(); ((AdoAdapter)db.GetAdapter()).UseSharedConnection(profiledCnn); book = db.Books.FindById(id); ((AdoAdapter)db.GetAdapter()).StopUsingSharedConnection(); } 
+3
source

There is a new hook that was added before Simple.Data , which improves integration with MiniProfiler.

AdoAdapter.ConnectionCreated += (o, args) => args.OverrideConnection(new ProfiledDbConnection((DbConnection)args.Connection, MiniProfiler.Current));

This basicallt allows you to connect to an event created by a connection and redefine it using its own profiled connection.

NOTE. Since writing this post, this change is not yet part of the nuget package. so you need your custom assembly Simple.Data

0
source

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


All Articles