<commit_before>﻿using System;
using System.Collections.Generic;
using System.Data;
using Debonair.FluentApi;

namespace Debonair.Utilities.Extensions
{
    public static class DbDataReaderExts
    {
        public static List<TEntity> MapTo<TEntity>(this IDataReader dr) where TEntity : class, new()
        {
            var list = new List<TEntity>();
            while (dr.Read())
            {
                var obj = Activator.CreateInstance<TEntity>();
                try
                {
                    var mapping = EntityMappingEngine.GetMappingForEntity<TEntity>();

                        foreach (var prop in obj.GetType().GetProperties())
                    {
                        var propMapping = mapping.GetMappingForType(prop);

                        if (propMapping.IsIgnored) continue;

                        var colName = !string.IsNullOrEmpty(propMapping.ColumnName) ? propMapping.ColumnName : prop.Name;

                        if (!HasColumn(dr, colName)) continue;

                        if (!Equals(dr[colName], DBNull.Value))
                        {
                            prop.SetValue(obj, dr[colName]);
                        }
                    }
                    list.Add(obj);

                }
                catch (Exception ex)
                {
                    throw;
                }

            }
            return list;
        }

        private static bool HasColumn(this IDataRecord dr, string colName)<commit_msg>Update DbDataReaderExts.cs<commit_after>﻿using System;
using System.Collections.Generic;
using System.Data;
using Debonair.FluentApi;

namespace Debonair.Utilities.Extensions
{
    public static class DbDataReaderExts
    {
        public static List<TEntity> MapTo<TEntity>(this IDataReader dr) where TEntity : class, new()
        {
            var list = new List<TEntity>();
            while (dr.Read())
            {
                var obj = Activator.CreateInstance<TEntity>();
                try
                {
                    var mapping = EntityMappingEngine.GetMappingForEntity<TEntity>();

                        foreach (var prop in obj.GetType().GetProperties())
                    {
                        var propMapping = mapping.GetMappingForType(prop);

                        if (propMapping.IsIgnored) continue;

                        var colName = prop.Name;
                        
                        if (!HasColumn(dr, colName)) continue;

                        if (!Equals(dr[colName], DBNull.Value))
                        {
                            prop.SetValue(obj, dr[colName]);
                        }
                    }
                    list.Add(obj);

                }
                catch (Exception ex)
                {
                    throw;
                }

            }
            return list;
        }

        private static bool HasColumn(this IDataRecord dr, string colName)
{'fraction_non_alphanumeric': 0.08203916272788657, 'fraction_numerical': 0.0, 'mean_word_length': 1.2144992526158445, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6267424', 'n_tokens_mistral': 735, 'n_tokens_neox': 679, 'n_words': 152}