//map datarow ==> an entity object public TEntity Map(DataRow row) { //Get field with datanames attribute only List <PropertyInfo> properties = GetDataNamesAttributeFields(); TEntity entity = new TEntity(); //for each field => set value with column has name equal to field valueName foreach (var prop in properties) { PropertyMapHelper.Map(typeof(TEntity), row, prop, entity); } return(entity); }
//map dataset ==> list of entity object public IEnumerable <TEntity> Map(DataTable table) { //Get field with datanames attribute only List <PropertyInfo> properties = GetDataNamesAttributeFields(); //create a list of TEntity List <TEntity> entities = new List <TEntity>(); foreach (DataRow row in table.Rows) { //create a corresponding TEntity for each row in table TEntity entity = new TEntity(); //for each field declared in TEntity (user-defined model) map it with PropertyMapHelper foreach (var prop in properties) { //for each field => set value with column has name equal to field valueName PropertyMapHelper.Map(typeof(TEntity), row, prop, entity); } //add object-transformed row to list entities.Add(entity); } return(entities); }