public Column CreateColumn(string tableName, string columnName)
        {
            FireEvent(PropertyNameFormatting, new SchemaExtractorEventArgs {
                Column = columnName
            });
            string propertyName = AvoidCollision(GetPropertyName(tableName, columnName), tableName, columnName);

            propertyName = AvoidNameOfContainingType(propertyName, tableName, columnName);
            NameMap.Set(new ColumnNameToPropertyName {
                ColumnName = columnName, PropertyName = propertyName, TableName = tableName
            });
            FireEvent(PropertyNameFormatted, new SchemaExtractorEventArgs {
                Column = columnName
            });

            Column column = new Column(columnName, GetColumnDataType(tableName, columnName))
            {
                PropertyName = propertyName,
                DataType     = GetColumnDataType(tableName, columnName),
                DbDataType   = GetColumnDbDataType(tableName, columnName),
                MaxLength    = GetColumnMaxLength(tableName, columnName),
                AllowNull    = GetColumnNullable(tableName, columnName)
            };

            return(column);
        }
        public virtual SchemaDefinition Extract(SchemaManager schemaManager)
        {
            SchemaDefinition result = new SchemaDefinition {
                Name = GetSchemaName()
            };

            schemaManager.CurrentSchema = result;

            // GetTableNames
            GetTableNames().Each(tableName =>
            {
                FireEvent(ProcessingTable, new SchemaExtractorEventArgs {
                    Table = tableName
                });

                FireEvent(ClassNameFormatting, new SchemaExtractorEventArgs {
                    Table = tableName
                });
                string className = GetClassName(tableName);
                NameMap.Set(new TableNameToClassName {
                    TableName = tableName, ClassName = className
                });
                FireEvent(ClassNameFormatted, new SchemaExtractorEventArgs {
                    Table = tableName
                });

                schemaManager.AddTable(tableName, className);//  add each table
                // GetColumnNames
                GetColumnNames(tableName).Each(columnName =>
                {
                    FireEvent(ProcessingColumn, new SchemaExtractorEventArgs {
                        Column = columnName
                    });
                    //  add each column;
                    schemaManager.AddColumn(tableName, CreateColumn(tableName, columnName));
                    FireEvent(ProcessingColumnComplete, new SchemaExtractorEventArgs {
                        Column = columnName
                    });
                });

                string keyColumnName = GetKeyColumnName(tableName);
                if (!string.IsNullOrEmpty(keyColumnName))
                {
                    schemaManager.SetKeyColumn(tableName, keyColumnName);
                }

                FireEvent(ProcessingTableComplete, new SchemaExtractorEventArgs {
                    Table = tableName
                });
            });

            // GetForeignKeyColumns
            GetForeignKeyColumns().Each(fk =>
            {
                FireEvent(ProcessingForeignKey, new SchemaExtractorEventArgs {
                    ForeignKeyColumn = fk
                });
                //  set each foreignkey
                schemaManager.SetForeignKey(fk.ReferencedTable, fk.TableName, fk.Name, GetKeyColumnName(fk.ReferencedTable), NameFormatter);
                FireEvent(ProcessingForeignComplete, new SchemaExtractorEventArgs {
                    ForeignKeyColumn = fk
                });
            });
            SaveNameMap(schemaManager);
            SetClassNamesOnColumns(schemaManager);
            return(result);
        }