示例#1
0
        /// <summary>
        /// Execute command and convert all rows into a list of objects.
        /// </summary>
        /// <typeparam name="T">Object type to create</typeparam>
        /// <returns>List of created objects</returns>
        public List <T> ReadAsObjects <T>() where T : new()
        {
            if (_log.IsTraceEnabled())
            {
                _log.TraceMethodCall("ReadAsObject<T>()", typeof(T).FullName, _command.CommandText);
            }
            Dictionary <string, DataColumnField> fields = GetDataFields(typeof(T));

            // read item from database
            List <T> result = new List <T>();

            Execute(delegate(IDataReader reader) {
                while (reader.Read())
                {
                    result.Add(FillObject(new T(), fields, reader));
                }
            });
            return(result);
        }