Ejemplo n.º 1
0
        /// <summary>
        /// Spits back a map of IEnumerable, or multiple items
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public IEnumerable <TEntity> 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(TEntity)).GetProperties()
                             .Where(x => x.GetCustomAttributes(typeof(DataNamesAttribute), true).Any())
                             .ToList();

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

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

            return(entities);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Spits back only one item
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public TEntity Map(DataRow row)
        {
            //Step 1 - Get the Column Names
            var columnNames = row.Table.Columns
                              .Cast <DataColumn>()
                              .Select(x => x.ColumnName)
                              .ToList();

            //Step 2 - Get the Property Data Names
            var properties = (typeof(TEntity)).GetProperties()
                             .Where(x => x.GetCustomAttributes(typeof(DataNamesAttribute), true).Any())
                             .ToList();

            //Step 3 - Map the data
            TEntity entity = new TEntity();

            foreach (var prop in properties)
            {
                PropertyMapHelper.Map(typeof(TEntity), row, prop, entity);
            }

            return(entity);
        }