Exemplo n.º 1
0
        private void Init()
        {
            var properties = new Dictionary <string, PropertyInfo>();

            foreach (var propertyInfo in EntityType.GetProperties())
            {
                properties[propertyInfo.Name] = propertyInfo;
            }

            var columnMaps   = new Dictionary <string, ColumnPropertyMapper>();
            var propertyMaps = new Dictionary <PropertyInfo, ColumnPropertyMapper>();

            for (var i = 0; i < DataReader.FieldCount; i++)
            {
                var columnName = DataReader.GetName(i);
                if (properties.ContainsKey(columnName))
                {
                    columnMaps[columnName] = new ColumnPropertyMapper(columnName, properties[columnName]);
                    propertyMaps[properties[columnName]] = new ColumnPropertyMapper(columnName, properties[columnName]);
                    continue;
                }

                var pascalName = columnName.ToPascalCase();
                if (properties.ContainsKey(pascalName))
                {
                    columnMaps[columnName] = new ColumnPropertyMapper(columnName, properties[pascalName]);
                    propertyMaps[properties[pascalName]] = new ColumnPropertyMapper(columnName, properties[pascalName]);
                    continue;
                }

                var camelName = columnName.ToCamelCase();
                if (properties.ContainsKey(camelName))
                {
                    columnMaps[columnName] = new ColumnPropertyMapper(columnName, properties[camelName]);
                    propertyMaps[properties[camelName]] = new ColumnPropertyMapper(columnName, properties[camelName]);
                }
            }

            ColumnMaps   = columnMaps.ToImmutableDictionary();
            PropertyMaps = propertyMaps.ToImmutableDictionary();
        }
Exemplo n.º 2
0
        private void Init()
        {
            var properties = new Dictionary <string, PropertyInfo>();

            foreach (var propertyInfo in EntityType.GetProperties())
            {
                properties[propertyInfo.Name] = propertyInfo;
            }

            var columnMaps   = new Dictionary <string, ColumnPropertyMapper>();
            var propertyMaps = new Dictionary <PropertyInfo, ColumnPropertyMapper>();

            foreach (DataColumn dataColumn in Table.Columns)
            {
                var columnName = dataColumn.ColumnName;
                if (properties.ContainsKey(columnName))
                {
                    columnMaps[columnName] = new ColumnPropertyMapper(columnName, properties[columnName]);
                    propertyMaps[properties[columnName]] = new ColumnPropertyMapper(columnName, properties[columnName]);
                    continue;
                }

                var pascalName = columnName.ToPascalCase();
                if (properties.ContainsKey(pascalName))
                {
                    columnMaps[columnName] = new ColumnPropertyMapper(columnName, properties[pascalName]);
                    propertyMaps[properties[pascalName]] = new ColumnPropertyMapper(columnName, properties[pascalName]);
                    continue;
                }

                var camelName = columnName.ToCamelCase();
                if (properties.ContainsKey(camelName))
                {
                    columnMaps[columnName] = new ColumnPropertyMapper(columnName, properties[camelName]);
                    propertyMaps[properties[camelName]] = new ColumnPropertyMapper(columnName, properties[camelName]);
                }
            }

            ColumnMaps   = columnMaps.ToImmutableDictionary();
            PropertyMaps = propertyMaps.ToImmutableDictionary();
        }