[英]Mini-Profiler with Simple.Data
Is it possible to use Mini-Profiler with Simple.Data Library? 是否可以将Mini-Profiler与Simple.Data库一起使用? I use it to get data from MySql like this:
我使用它来从MySql获取数据,如下所示:
var db = Database.OpenConnection(ConnectionString);
var book = db.Books.FindById(id);
How can I user Profiler with this code? 如何使用此代码使用Profiler?
You can tell Simple.Data to use a pre-existing connections and wrap your connection with a profiled connection: 您可以告诉Simple.Data使用预先存在的连接并使用配置文件连接包装您的连接:
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. Simple.Data
中添加了一个新的钩子,可以更好地与Simple.Data
集成。
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. 此basicallt允许您连接到创建的连接事件,并使用您自己的配置文件连接覆盖它。
NOTE: As of writing of this post, this change isn't in the nuget package yet. 注意:截至撰写本文时,此更改尚未在nuget包中。 so you need your custom build of
Simple.Data
所以你需要自定义的
Simple.Data
构建
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.