从.NET中的数据库中检索数据的最快方法?

时间:2011-09-25 22:00:30

标签: .net ado.net

使用ADO.NET,从数据库中检索数据并将数据填充到业务对象中的最快方法是什么?

我应该使用哪一个? DBDataReaderDBDataAdapter或任何其他类?

有没有办法让这个过程自动化?假设基于属性名称并将它们与数据库字段名称匹配?

3 个答案:

答案 0 :(得分:8)

这听起来与ORM或微型ORM完全相同。这是dapper-dot-netperformance tests的输出(大约1分钟前运行,在PC上也忙于进行一些转码,因此不是100%可靠 - 请自己运行)...这也是一个非常有限的测试 - 一如既往,测试应该代表您的特定环境 - 但由于我们无法预测您的环境,我们改用环境!我将“小巧”标记为<==== dapper

Running 500 iterations that load up a post entity
Mapper Query (non-buffered) took 57ms          <==== dapper
hand coded took 57ms
Dynamic Mapper Query (buffered) took 58ms      <==== dapper
PetaPoco (Fast) took 58ms
Dynamic Mapper Query (non-buffered) took 59ms  <==== dapper
Mapper Query (buffered) took 60ms              <==== dapper
Dapper.Cotrib took 60ms                        <==== dapper
PetaPoco (Normal) took 66ms
Dynamic Massive ORM Query took 67ms
BLToolkit took 88ms
Simple.Data took 96ms
Linq 2 SQL Compiled took 99ms
NHibernate Session.Get took 127ms
SubSonic Coding Horror took 128ms
Entity framework CompiledQuery took 130ms
NHibernate HQL took 132ms
NHibernate SQL took 134ms
NHibernate Criteria took 173ms
Soma took 184ms
Linq 2 SQL ExecuteQuery took 230ms
Linq 2 SQL took 694ms
NHibernate LINQ took 700ms
Entity framework ESQL took 730ms
Entity framework ExecuteStoreQuery took 735ms
Entity framework took 991ms
Entity framework No Tracking took 1011ms
SubSonic ActiveRecord.SingleOrDefault took 4345ms
(end of tests; press any key)

答案 1 :(得分:5)

如果您想要自动化,那么您正在寻找一个orm。你可以查看一些较轻的,如大块,ormlite,小巧玲珑和PetaPoco。

答案 2 :(得分:4)

  

使用ADO.NET,从数据库中检索数据并将数据填充到业务对象中的最快方法是什么?

     

有没有办法让这个过程自动化?让我们说基于属性名称并将它们与数据库字段名称匹配?

Dapper。绝对是炽热的。