title: Using nHibernate to retrieve Database Schema
body: <p>Is it possible to generate a schema of a database from nHibernate, where I have provided nHibernate with the configuration to the database but I have not written any mappings. </p>
  
  <p>I wish to get the Database MetaData/Schema programmatically. </p>
  
  <p>I am using an Oracle Database. I have tried two approaches:</p>
  
  <p><strong>Approach one:</strong> </p>
  
  <pre><code>    public DatabaseMetadata GetMetadata(DbConnection connectionIn)
      {
          return new DatabaseMetadata(connectionIn, _dialect);
      }
  </code></pre>
  
  <p><strong><em>Problem:</em></strong> This seems to be what I need however, although it correctly connects, it hasn't picked up any of my tables. All I provided was the nHibernate Configuration object which was populated with the contents of my nHibernate.xml.config file (connection string, driver client, etc). </p>
  
  <p><strong><em>Question:</em></strong> Why would it not return the table data? It's connected correctly but finds nothing! </p>
  
  <p><strong>Approach two:</strong></p>
  
  <pre><code> public void DatabaseSchema()
   {
       var schema = new SchemaExport(nHibernateConfiguration);
       schema.SetOutputFile("schema.dll");
        schema.Create(true, true);
   }
  </code></pre>
  
  <p>nHibernateConfiguration is an instance (property on class) of the nHibernate Configuration object, populated with contents from the nHibernate.xml.config class. </p>
  
  <p><strong><em>Problem:</em></strong> This simply doesn't work. Crashes with the following exception:</p>
  
  <blockquote>
    <p>NHibernate.MappingException : Dialect
    does not support identity key
    generation</p>
  </blockquote>
  
  <p>I suspect this will only generate a schema based on mappings you have created? I have created no mappings. The idea is this will work against whichever database I have connected to a generate a schema for it. </p>
  
  <p><strong><em>Question:</em></strong> Is my belief that this method will only generate a Schema based on my mappings? If not, Am I using it correctly? </p>
  
  <p>Hopefully this is clear enough, comment if I need to provide more info. </p>
  
  <p>Thanks In Advance. </p>
  
  <p>To be clear: I have a database and want to get meta data representing the database, a schema. </p>