/// <summary> /// 把DataReader当前数据赋值给一个实体对象,注意方法不负责回收DataReader对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dr"></param> /// <returns></returns> public static T ToEntity <T>(IDataReader dr) where T : class, new() { if (dr == null) { return(default(T)); } var builder = DataReaderEntityBuilder <T> .CreateBuilder(dr); return(builder.Build(dr)); }
/// <summary> /// 把DataReader中数据赋值给一个List对象,注意方法不负责回收DataReader对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="dr"></param> /// <returns></returns> public static List <T> ToList <T>(IDataReader dr) where T : class, new() { var list = new List <T>(); if (dr == null) { return(list); } var builder = DataReaderEntityBuilder <T> .CreateBuilder(dr); while (dr.Read()) { list.Add(builder.Build(dr)); } return(list); }