コード例 #1
0
        public IEnumerable <TEntity> Map(DataTable table)
        {
            //Step 1 - Get the Column Names
            var tableColumnNames = 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();

            //PropertyMapHelper.ValidateColumnsMatch(typeof(TEntity), table, properties);

            //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);
        }
コード例 #2
0
        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);
        }