Beispiel #1
0
        /// <summary>
        /// Maps the data row.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="mapping">The mapping.</param>
        /// <param name="dataRow">The data row.</param>
        /// <returns></returns>
        private static T MapDataRow <T>(ClassMap <T> mapping, DataRow dataRow) where T : new()
        {
            var result = new T();

            foreach (IPropertyMappingProvider mappingProvider in mapping.Properties)
            {
                PropertyMapping propertyMapping = mappingProvider.GetPropertyMapping();
                try
                {
                    propertyMapping.PropertyInfo.SetValue(result, dataRow[propertyMapping.ColumnName], null);
                }
                catch (Exception e)
                {
                    HandleMappingException(e, propertyMapping);
                }
            }
            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// Maps the data reader.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="mapping">The mapping.</param>
        /// <param name="dataReader">The data reader.</param>
        /// <returns></returns>
        private static T MapDataReader <T>(ClassMap <T> mapping, IDataReader dataReader) where T : new()
        {
            var result = new T();

            foreach (IPropertyMappingProvider mappingProvider in mapping.Properties)
            {
                PropertyMapping propertyMapping = mappingProvider.GetPropertyMapping();
                try
                {
                    int ordinal = dataReader.GetOrdinal(propertyMapping.ColumnName);
                    propertyMapping.PropertyInfo.SetValue(result, dataReader.GetValue(ordinal), null);
                }
                catch (Exception e)
                {
                    HandleMappingException(e, propertyMapping);
                }
            }
            return(result);
        }