Esempio n. 1
0
        /// <summary>
        /// 返回匿名类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="reader"></param>
        /// <param name="resultSelector"></param>
        /// <param name="runTime"></param>
        /// <returns></returns>
        public static List <TResult> DataReaderToDynamic <T, TResult>(System.Data.Common.DbDataReader reader, Expression <Func <T, TResult> > resultSelector, out double runTime) where T : IModel, new()
        {
            var            time     = DateTime.Now;
            List <TResult> list     = new List <TResult>();
            var            typeArry = TypeCache.GetProperties(typeof(T), true).Values;
            var            columns  = new Dictionary <string, int>();

            for (int i = 0; i < reader.FieldCount; i++)
            {
                columns.Add(reader.GetName(i).ToLower(), i);
            }
            var reflection = ReflectionHelper.GetInfo <T>();
            var actions    = new List <CRL.ObjectConvert.ActionItem <T> >();
            var first      = true;

            //var objOrigin = new T();
            while (reader.Read())
            {
                object objInstance = reflection.CreateObjectInstance();

                object[] values = new object[columns.Count];
                reader.GetValues(values);
                var detailItem = ObjectConvert.DataReaderToObj <T>(columns, values, reflection, true, objInstance, typeArry, actions, first) as T;
                var result     = resultSelector.Compile()(detailItem);
                list.Add(result);
                first = false;
            }
            reader.Close();
            runTime = (DateTime.Now - time).TotalMilliseconds;
            return(list);
        }
Esempio n. 2
0
        public static List <TResult> DataReaderToDynamic <T, TResult>(System.Data.Common.DbDataReader reader, Expression <Func <T, TResult> > resultSelector, ParameCollection fieldMapping) where T : IModel, new()
        {
            List <TResult> list     = new List <TResult>();
            var            typeArry = TypeCache.GetProperties(typeof(T), true).Values;

            while (reader.Read())
            {
                var detailItem = ObjectConvert.DataReaderToObj(reader, typeof(T), typeArry, fieldMapping) as T;
                var result     = resultSelector.Compile()(detailItem);
                list.Add(result);
            }
            reader.Close();
            return(list);
        }
Esempio n. 3
0
        /// <summary>
        /// 返回匿名类型
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TResult"></typeparam>
        /// <param name="reader"></param>
        /// <param name="resultSelector"></param>
        /// <param name="runTime"></param>
        /// <returns></returns>
        public static List <TResult> DataReaderToDynamic <T, TResult>(System.Data.Common.DbDataReader reader, Expression <Func <T, TResult> > resultSelector, out double runTime) where T : IModel, new()
        {
            var            time     = DateTime.Now;
            List <TResult> list     = new List <TResult>();
            var            typeArry = TypeCache.GetProperties(typeof(T), true).Values;

            while (reader.Read())
            {
                var detailItem = ObjectConvert.DataReaderToObj(reader, typeof(T), typeArry) as T;
                var result     = resultSelector.Compile()(detailItem);
                list.Add(result);
            }
            reader.Close();
            runTime = (DateTime.Now - time).TotalMilliseconds;
            return(list);
        }