Sorting Collections

SchemaExplorer retrieves the various collections in the order that the database presents them. For all practical purposes, this means that the collections are in a random order. Often, you'll want a collection sorted by name instead. This is easily accomplished by creating a second collection of the same type and using the Sort method:

TableSchemaCollection tables = new TableSchemaCollection(SourceDatabase.Tables);
tables.Sort(new PropertyComparer("Name"));

After running this code, the new tables collection will contain all of the tables from the source database, sorted by name.