Dapper Vs Dbentry

來源:互聯網
上載者:User

標籤:

公司項目資料庫訪問採用的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]

Dapper Vs Dbentry

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.