Esempio n. 1
0
        public EntityMapper(Type type)
        {
            var attributesOfClass = type.GetCustomAttributes(false);

            foreach (object attribute in attributesOfClass)
            {
                TableAttribute tableAttribute = attribute as TableAttribute;
                if (tableAttribute != null)
                {
                    this.TableName = tableAttribute.TableName;
                }
            }

            foreach (var property in type.GetProperties())
            {
                // TODO: add prop - field and field - prop dictionary
                string propOfEntity  = property.Name;
                string columnOfTable = null;
                if (property.IsDefined(typeof(ColumnAttribute), false))
                {
                    var attributesOfProperty = property.GetCustomAttributes(false);

                    foreach (object attribute in attributesOfProperty)
                    {
                        ColumnAttribute columnAttribute = attribute as ColumnAttribute;
                        if (columnAttribute != null)
                        {
                            columnOfTable = columnAttribute.ColumnName;
                        }
                    }
                    // TODO: add primary key
                }
                else if (property.IsDefined(typeof(PrimaryKeyColumn), false))
                {
                    var attributesOfProperty = property.GetCustomAttributes(false);

                    foreach (object attribute in attributesOfProperty)
                    {
                        PrimaryKeyColumn primaryColumnAttribute = attribute as PrimaryKeyColumn;
                        if (primaryColumnAttribute != null)
                        {
                            columnOfTable = primaryColumnAttribute.ColumnName;
                            primaryKeyProperty.Add(propOfEntity, primaryColumnAttribute.ColumnType);
                        }
                    }
                }
                else
                {
                    continue;
                }
                this.databaseToEntity.Add(columnOfTable, propOfEntity);
                this.entityToDatabase.Add(propOfEntity, columnOfTable);
                // TODO: add rule
                this.rules.Add(new PropertyMappingRule(propOfEntity,
                                                       columnOfTable,
                                                       MappingEngine.GetEngineFromName(MappingEngineType.TableField)));
            }
        }
Esempio n. 2
0
 public PropertyMappingRule(string propertyName, string columnName, MappingEngine mapping)
 {
     this.propertyName = propertyName;
     this.columnName   = columnName;
     this.mapping      = mapping;
 }