Exemple #1
0
        /// <summary>
        /// Map all the rows to IList of objects T using DataReader
        /// </summary>
        /// <param name="connection"></param>
        /// <param name="sql"></param>
        /// <param name="rowmapper"></param>
        /// <param name="onAfterRowsMapped"></param>
        /// <returns></returns>
        public static IList <T> MapRows <T>(string connection, string sql, Func <IDataReader, int, T> rowmapper, Action <IList <T> > onAfterRowsMapped = null)
        {
            Data.Database db      = new Data.Database(connection);
            IList <T>     records = new List <T>();

            db.ExecuteReaderText(sql, reader =>
            {
                int ndx = 0;
                while (reader.Read())
                {
                    T record = rowmapper(reader, ndx);
                    records.Add(record);
                    ndx++;
                }
                if (onAfterRowsMapped != null)
                {
                    onAfterRowsMapped(records);
                }
            }, null);

            return(records);
        }