/// <summary> /// Maps all the rows using DataTable. /// </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 <DataTable, int, T> rowmapper, Action <IList <T> > onAfterRowsMapped = null) { Data.Database db = new Data.Database(connection); DataTable table = db.ExecuteDataTableText(sql); if (table == null || table.Rows == null || table.Rows.Count == 0) { return(new List <T>()); } IList <T> records = new List <T>(); for (int ndx = 0; ndx < table.Rows.Count; ndx++) { T record = rowmapper(table, ndx); records.Add(record); } if (onAfterRowsMapped != null) { onAfterRowsMapped(records); } return(records); }