示例#1
0
        /// <summary>
        /// DataReader转换为list
        /// </summary>
        /// <typeparam name="T">要转换的类型</typeparam>
        /// <param name="reader">DataReader对象</param>
        /// <returns></returns>
        public static IList <T> DataReaderToList <T>(IDataReader reader) where T : new()
        {
            DynamicBuilder <T> builder = DynamicBuilder <T> .CreateBuilder(reader);

            IList <T> list = new List <T>();

            while (reader.Read())
            {
                list.Add(builder.Build(reader));
            }
            reader.Close();
            return(list);
        }
示例#2
0
        /// <summary>
        /// DataReader转换为实体
        /// </summary>
        /// <typeparam name="T">转换的类型</typeparam>
        /// <param name="reader">DataReader对象</param>
        /// <returns></returns>
        public static T DataReaderToObject <T>(IDataReader reader) where T : new()
        {
            var obj = new T();

            if (reader.Read())
            {
                DynamicBuilder <T> builder = DynamicBuilder <T> .CreateBuilder(reader);

                obj = builder.Build(reader);
            }
            else
            {
                obj = default(T);
            }
            reader.Close();
            return(obj);
        }