问题根源:现在编码已经习惯了面向对象编码,数据库访问层也由ORM代替了ADO,DataTable一般用的越来越少,可是一些公用方法还是用到DataTable了,理由其实很简单就是公用方法里不用DataTable就得用反射访问实体集合,反射的访问效率比DataTable低很多是毋庸置疑的。可是我还是觉得很苦恼,心中有两个疑问:
1、访问实体集合到底比访问DataTable慢多少呢?
2、后台数据层提供的是实体集合,调用公用方法势必要转为DataTable,那转换耗时多少呢?
接下来我新建了一个控制台程序,简单写了一个实体对象:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
1 public class TestEntity 2 { 3 public string Col1 { get; set; } 4 public string Col2 { get; set; } 5 public string Col3 { get; set; } 6 public string Col4 { get; set; } 7 public string Col5 { get; set; } 8 public string Col6 { get; set; } 9 public string Col7 { get; set; } 10 public string Col8 { get; set; } 11 public string Col9 { get; set; } 12 public string Col10 { get; set; } 13 public string Col11 { get; set; } 14 public string Col12 { get; set; } 15 public string Col13 { get; set; } 16 public string Col14 { get; set; } 17 public string Col15 { get; set; } 18 public string Col16 { get; set; } 19 public string Col17 { get; set; } 20 public string Col18 { get; set; } 21 public string Col19 { get; set; } 22 public string Col20 { get; set; } 23 public string Col21 { get; set; } 24 public string Col22 { get; set; } 25 public string Col23 { get; set; } 26 public string Col24 { get; set; } 27 public string Col25 {