SchemaExplorer is CodeSmithCodeSmith Generator's built-in interface for working with metadata from databases. You can use the classes in SchemaExplorer either programmatically or interactively; often, you'll combine the two approaches. For example, you may want to allow the user to interactively select a database, and then programmatically build a list of all of the tables in the selected database. Here's a template that demonstrates using SchemaExplorer for this purpose:
...
Before you can execute this template, you must supply a value for the SourceDatabase property. When you place your cursor in the property sheet row for this property, CodeSmith will Generator will display a builder button (highlighted in green), indicating that there is an external editor hooked up for this property. CodeSmith automatically Generator automatically uses editors built into SchemaExplorer:
Clicking the builder button opens the Database Picker dialog box. A dropdown list lets you choose from all of the data sources that you have previously defined on your computer. There's also a builder button to define a new data source:
...
If you choose to add a new data source, SchemaExplorer opens the Data Source dialog box. To add a new data source, you must provide a name for the new data source, then select a provider type and type in a connection string. CodeSmith ships with providers for SQL Server and ADOX data sources.
It's worth noting that CodeSmith Generator ships with many database providers including the following:
- ADOXSchemaProvider
- ISeriesSchemaProvider
- MySQLSchemaProvider
- OracleSchemaProvider
- PostgreSQLSchemaProvider
- SQLAnywhereSchemaProvider
- SqlCompactSchemaProvider
- SQLiteSchemaProvider
- SqlSchemaProvider
- VistaDBSchemaProvider
Here's a sample of the output for this template when it's used with the SQL Server Northwind sample database:
...
After the user specifies the SourceDatabase, CodeSmith is Generator is able to use it as the root of an object model of the entire database.
...
Widget Connector | ||||||
---|---|---|---|---|---|---|
|
Info |
---|
Refer to the CodeSmith Generator API Reference for a complete listing of the classes and members within the SchemaExplorer library. |
...