zoukankan      html  css  js  c++  java
  • Dapper with MVC MiniProfiler

    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的执行时间:

     

  • 相关阅读:
    light oj 1007
    51nod 1298 圆与三角形
    codeforces 899C Dividing the numbers
    zznu 1996 : 正三角形和圆的爱情
    zznu 2081 : 舰队管理
    zzun 2076 : 三花聚顶神功
    zznu 2054 : 油田
    机械设备--第九届省赛--深搜
    设计模式-单例模式、工厂模式
    Spring Boot 遇到空指针
  • 原文地址:https://www.cnblogs.com/abcdwxc/p/5430770.html
Copyright © 2011-2022 走看看