Is it possible to use Mini-Profiler with Simple.Data Library? I use it to get data from MySql like this:
var db = Database.OpenConnection(ConnectionString);
var book = db.Books.FindById(id);
How can I user Profiler with this code?
Is it possible to use Mini-Profiler with Simple.Data Library? I use it to get data from MySql like this:
var db = Database.OpenConnection(ConnectionString);
var book = db.Books.FindById(id);
How can I user Profiler with this code?
You can tell Simple.Data to use a pre-existing connections and wrap your 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();
}
There is a new hook that was added to Simple.Data
which allows for better integration with MiniProfiler.
AdoAdapter.ConnectionCreated += (o, args) => args.OverrideConnection(new ProfiledDbConnection((DbConnection)args.Connection, MiniProfiler.Current));
This basicallt allows you to hookup to the connection created event and override it with your own profiled connection.
NOTE: As of writing of this post, this change isn't in the nuget package yet. so you need your custom build of Simple.Data