惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
Check Point Blog
美团技术团队
Microsoft Security Blog
Microsoft Security Blog
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
G
Google Developers Blog
博客园 - 聂微东
爱范儿
爱范儿
博客园 - 叶小钗
J
Java Code Geeks
月光博客
月光博客
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
The Cloudflare Blog
宝玉的分享
宝玉的分享
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
小众软件
小众软件
WordPress大学
WordPress大学
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Vercel News
Vercel News
Y
Y Combinator Blog
量子位

博客园 - 五味果

.net Core 调用微信Jsapi接口,H5解析二维码 TextBoxFor控件的扩展---Bootstrap在mvc上的应用 外地手机号码,请在号码前加拨0 Sql 2012 远程数据库连接 DbEntry在Vs2012里的配置 终点,也是新的起点! 天气预报数据查询接口 关于浏览器账号的一个愿望 关于移动,联通,电信的区分。 - 五味果 - 博客园 被#号折腾了。 Orm 请别让数据库中的默认值形同虚设!! 利用反射,泛型,静态方法快速获取表单值到Model。 subsonic sqlite 路径问题 - 五味果 ORM是工具,工具是用来提高开发速度的。 基于XML的后台管理系统--设想 项模板的使用--提高编程速度 C#开发编码规范 基于Jquery的内容显示模块 - 五味果 - 博客园 IIS7下运行Access+Asp的解决方法
Dapper Vs Dbentry
五味果 · 2015-02-11 · via 博客园 - 五味果

公司项目数据库访问采用的dapper,以前没有用过。今天简单的测试下了,dapper和dbentry 查询效率情况。

  public ActionResult Test()
        {
            Sys_UserFacade su = new Sys_UserFacade();      
           var result = string.Empty;
           System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
           sw.Start();
           var list = su.GetSys_UserList();
           sw.Stop();
           result += "Dapper:查询" + list.Count() + "条数据耗时" + sw.ElapsedMilliseconds + "毫秒 ";
           sw.Reset();
           sw.Start();
           var list2 = SysUser.Find(u=>u.LoginCount==2);
          
           sw.Stop();
           result += "Vs Dbentry:" + list2.Count() + "条数据耗时" + sw.ElapsedMilliseconds + "毫秒<hr/>";         
           return Content(result);
        }

sql 2012 ,本机,140W+数据,进行了简单的全表查询,和条件查询。执行效率如下:

Dapper:查询1408128条数据耗时7474毫秒 Vs Dbentry:1408064条数据耗时6370毫秒
Dapper:查询1408128条数据耗时7372毫秒 Vs Dbentry:1408064条数据耗时6453毫秒
Dapper:查询1408128条数据耗时7423毫秒 Vs Dbentry:1408064条数据耗时6466毫秒
Dapper:查询1408128条数据耗时7288毫秒 Vs Dbentry:1408064条数据耗时6646毫秒
Dapper:查询1408128条数据耗时7172毫秒 Vs Dbentry:1408064条数据耗时6667毫秒
Dapper:查询128条数据耗时50毫秒 Vs Dbentry:128条数据耗时30毫秒
Dapper:查询128条数据耗时47毫秒 Vs Dbentry:128条数据耗时29毫秒
Dapper:查询128条数据耗时42毫秒 Vs Dbentry:128条数据耗时30毫秒
Dapper:查询128条数据耗时41毫秒 Vs Dbentry:128条数据耗时38毫秒
Dapper:查询128条数据耗时44毫秒 Vs Dbentry:128条数据耗时29毫秒

总结:两个效率差不多,dbentry 略胜一点。

今天使用dapper时候遇到一个小问题,数据库连接字符串在web.config配置如下

<connectionStrings>
<add name="SmDbConnectionString" connectionString="Data Source=(local);Initial Catalog=***;User ID=xxx;Password=xxxx" providerName="System.Data.SqlClient" />
</connectionStrings>

在程序中采用

 cnnStringName = ConfigurationManager.ConnectionStrings[0].Name;  

访问连接字符串名,发现返回的连接名并不是想要的。而是继承了Machine.config中的连接。

解决办法:

1:在web.config connectionStrings节点中先添加个 <clear/>

2:或者直接ConfigurationManager.ConnectionStrings[1]