/// <summary>
        /// Gets all tables (plus constraints, indexes and triggers).
        /// </summary>
        public IList <DatabaseTable> AllTables(CancellationToken ct)
        {
            var loader  = new AllTablesLoader(_schemaReader, Exclusions);
            var handler = ReaderProgress;

            if (handler != null)
            {
                loader.ReaderProgress += RaiseReadingProgress;
            }
            var tables = loader.Load(ct);

            if (ct.IsCancellationRequested)
            {
                return(tables);
            }

            DatabaseSchema.Tables.Clear();
            DatabaseSchema.Tables.AddRange(tables);
            UpdateReferences();

            if (DatabaseSchema.DataTypes.Count > 0)
            {
                DatabaseSchemaFixer.UpdateDataTypes(DatabaseSchema);
            }

            _schemaReader.PostProcessing(DatabaseSchema);

            return(tables);
        }
Exemple #2
0
        /// <summary>
        /// Gets all tables (plus constraints, indexes and triggers).
        /// </summary>
        public IList <DatabaseTable> AllTables()
        {
            DataTable tabs = _sr.Tables();
            //get full datatables for all tables, to minimize database calls

            //we either use the converters directly (DataTable to our db model)
            //or loaders, which wrap the schema loader calls and converters
            //loaders hide the switch between calling for all tables, or a specific table
            var columnLoader     = new ColumnLoader(_sr);
            var constraintLoader = new SchemaConstraintLoader(_sr);
            var indexLoader      = new IndexLoader(_sr);

            DataTable ids = _sr.IdentityColumns(null);

            DataTable triggers         = _sr.Triggers(null);
            var       triggerConverter = new TriggerConverter(triggers);

            var tables = SchemaConverter.Tables(tabs);

            tables.Sort(delegate(DatabaseTable t1, DatabaseTable t2)
            {
                //doesn't account for mixed schemas
                return(string.Compare(t1.Name, t2.Name, StringComparison.OrdinalIgnoreCase));
            });


            foreach (DatabaseTable table in tables)
            {
                var tableName       = table.Name;
                var databaseColumns = columnLoader.Load(tableName);
                table.Columns.AddRange(databaseColumns);

                var pkConstraints = constraintLoader.Load(tableName, ConstraintType.PrimaryKey);
                PrimaryKeyLogic.AddPrimaryKey(table, pkConstraints);

                var fks = constraintLoader.Load(tableName, ConstraintType.ForeignKey);
                table.AddConstraints(fks);

                table.AddConstraints(constraintLoader.Load(tableName, ConstraintType.UniqueKey));
                table.AddConstraints(constraintLoader.Load(tableName, ConstraintType.Check));

                indexLoader.AddIndexes(table);

                SchemaConstraintConverter.AddIdentity(ids, table);
                table.Triggers.Clear();
                table.Triggers.AddRange(triggerConverter.Triggers(tableName));
                _sr.PostProcessing(table);
            }
            DatabaseSchema.Tables.Clear();
            DatabaseSchema.Tables.AddRange(tables);
            UpdateReferences();

            if (DatabaseSchema.DataTypes.Count > 0)
            {
                DatabaseSchemaFixer.UpdateDataTypes(DatabaseSchema);
            }

            _sr.PostProcessing(DatabaseSchema);

            return(tables);
        }