记得在学校的时候,接触得最多的就是SqlHelper,每次在读取的时候不管是DataTable还是DataReader转换为实体对象的时候是最恼火的,因为要写很多代码,而且没有什么意义.后面接触到了反射,于是查了下资料也写了个已经烂大街的DataTable转换为Model实体对象 public static IEnumerable<T> DataTableToModels<T>(this DataTable dt) where T : class, new() { //判断data…
Mapper类 using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace CommonHelper { public class Mapper { public…
在开发中可能会遇到这几种情况 1.EF或LINQ查询出来的匿名对象在其它地方调用不方便,又懒的手动建实体类 2.通过datatable反射实体需要先建一个类 ,头痛 3.通过SQL语句返回的实体也需要先建一个类 ,头痛 4.如果通过代码生成器要写模版,需要安装或者不想生成一堆不用的类 为了解决上面的不便之处,我封装了一个实体生成类,可以扔到程序里面任意调用 封装类: using System; using System.Collections.Generic; using System.Linq…