Terry's blog

Focus on bigdata and cloud.

博客园 首页 新随笔 联系 订阅 管理

Dapper是一个轻型的ORM类。代码就一个SqlMapper.cs文件,主要是IDbConnection的扩展方法,编译后就118K的一个很小的dll。官方站点http://code.google.com/p/dapper-dot-net/ 

MVC MiniProfiler是Stack Overflow团队设计的一款对ASP.NET MVC的性能分析的小程序。可以对一个页面本身,及该页面通过直接引用、Ajax、Iframe形式访问的其它页面进行监控,监控内容包括数据库内容,并可以显示数据库访问的SQL(支持EF、EF CodeFirst等 )。并且以很友好的方式展现在页面上。

该Profiler的一个特别有用的功能是它与数据库框架的集成。除了.NET原生的 DbConnection类,profiler还内置了对实体框架(Entity Framework)以及LINQ to SQL的支持。任何执行的Step都会包括当时查询的次数和所花费的时间。为了检测常见的错误,如N+1反模式,profiler将检测仅有参数值存在差 异的多个查询。

MiniProfiler是以Apache License V2.0协议发布的,你可以在NuGet找到。配置及使用可以看这里:http://code.google.com/p/mvc-mini-profiler(MVC MiniProfiler 描述摘自张善友的文章 http://www.cnblogs.com/shanyou/archive/2012/04/03/2430977.html)

 

以上两款开源项目都在StackOverflow 上使用。当然我们也可以使用MVC MiniProfiler 来对Dapper中的sql执行时间进行监视,方法如下:

 public static List<Contact> GetContacts(string sqlConnectionString)
        {
           // List<Contact> userList = new List<Contact>();
            var conn = new ProfiledDbConnection(new SqlConnection(sqlConnectionString), MiniProfiler.Current);
            conn.Open();
            var result = conn.Query<Contact>("select * from dbo.Contact where id>@id"new { id = 0 });
            return result.ToList();           
       

 

查看页面 Dapper中SQL的执行时间:

 

 

posted on 2016-04-25 14:07  王晓成  阅读(1856)  评论(0编辑  收藏  举报