Beispiel #1
0
        public IEnumerable <T> Map(DataTable table)
        {
            //Step 1 - Get the Column Names
            var columnNames = table.Columns.Cast <DataColumn>().Select(x => x.ColumnName).ToList();

            //Step 2 - Get the Property Data Names
            var properties = typeof(T).GetProperties();

            //Step 3 - Map the data
            List <T> entities = new List <T>();

            foreach (DataRow row in table.Rows)
            {
                T entity = new T();
                foreach (var prop in properties)
                {
                    PropertyMapHelper.Map(typeof(T), row, prop, entity);
                }
                entities.Add(entity);
            }

            return(entities);
        }