CodeSmith Community
Your Code. Your Way. Faster!

TableSchema does not get Foreign Keys

Latest post 02-16-2007 10:24 AM by apittman. 0 replies.
  • 02-16-2007 10:24 AM

    • apittman
    • Not Ranked
    • Joined on 03-21-2006
    • Posts 6
    • Points 90

    TableSchema does not get Foreign Keys

    I am having a problem with getting the Foreign Keys from TableSchema object. I am programmactically creating list of objects that contains DatabaseSchema property and two TableSchemaCollection properties. This list is populated in primary template and then passed to sub-templates to create my code. The tables in the two collections seem to have all of the other information except the ForeignKeys and I am not sure why. I figure I am I must be doing something wrong in the instantiation of the TableSchema object. 

     Here is my custom object code:

     public class DatabaseInfo
    {
     #region Private Fields
     
     private string _connectionStringName;
     private DatabaseSchema _schema = new DatabaseSchema();
     private TableSchemaCollection _entityTables = new TableSchemaCollection();
     private TableSchemaCollection _lazyLoadedEntityTables = new TableSchemaCollection();
     
     #endregion
     
     #region Public Properties
     
     public string ConnectionStringName
     {
      get { return _connectionStringName; }
     }
     public DatabaseSchema Schema
     {
      get { return _schema; }
     }
     public TableSchemaCollection EntityTables
     {
      get { return _entityTables; }
     }
     public TableSchemaCollection LazyLoadedEntityTables
     {
      get { return _lazyLoadedEntityTables; }
     }
     
     #endregion
     
     #region Constructor
     
     public DatabaseInfo(string connectionStringName, string connectionString, string providerName)
     {
      IDbSchemaProvider provider;
      switch(providerName)
      {
       case "SqlSchemaProvider":
        provider = new SqlSchemaProvider();
        break;
       case "ADOXSchemaProvider":
        provider = new ADOXSchemaProvider();
        break;
       default:
        throw new Exception("Provider not found.");
      }
      this._connectionStringName = connectionStringName;
      this._schema.ConnectionString = connectionString;
      this._schema.Provider = provider;
     }
     public DatabaseInfo(string connectionStringName, string connectionString, IDbSchemaProvider provider)
     {
      this._connectionStringName = connectionStringName;
      this._schema.ConnectionString = connectionString;
      this._schema.Provider = provider;
     }
     
     #endregion
    }

     Here is the code where I populate the list of DatabaseInfo objects:

    this.DatabaseList = new List<DatabaseInfo>();
     DatabaseInfo info;
     foreach(_CodeSmith.DataSourceDatabase database in DataSource.Databases)
     {
      info = new DatabaseInfo(database.ConnectionStringName, database.ConnectionString, database.ProviderType);
      
      foreach(_CodeSmith.DataSourceDatabaseSourceTable sourceTable in database.SourceTables)
      {
       info.EntityTables.Add(new TableSchema(info.Schema, sourceTable.Name, sourceTable.Owner, DateTime.Now));
      }
      
      foreach(_CodeSmith.DataSourceDatabaseLazyLoadedEntityTable lazyLoadTable in database.LazyLoadedEntityTables)
      {
       info.LazyLoadedEntityTables.Add(new TableSchema(info.Schema, lazyLoadTable.Name, lazyLoadTable.Owner, DateTime.Now));
      }
      
      this.DatabaseList.Add(info);
     }

     Thanks in advance for any advice.

    Aaric

    Thanks, Aaric Pittman
    Filed under: ,
    • Post Points: 5
Page 1 of 1 (1 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems