title: What is schemaExport in Fluent NHibernate?
body: <p>I am curious to know more on how this code and what is expected when executed.</p>
  
  <pre><code>        /// &lt;summary&gt;
          /// Sets up NHibernate, and adds an ISessionFactory to the given
          /// container.
          /// &lt;/summary&gt;
          private void ConfigureNHibernate(IKernel container)
          {
              // Build the NHibernate ISessionFactory object
              var sessionFactory = FluentNHibernate
                  .Cfg.Fluently.Configure()
                  .Database(
                      MsSqlConfiguration.MsSql2008.ConnectionString(
                          c =&gt; c.FromConnectionStringWithKey("ServicesDb")))
                  .CurrentSessionContext("web")
                  .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;SqlCommandFactory&gt;())
                  //.ExposeConfiguration(cfg =&gt; new SchemaUpdate(cfg).Execute(true, true))
                  .ExposeConfiguration(cfg =&gt;
                                           {
                                               var schemaExport = new SchemaExport(cfg);
                                               schemaExport.Drop(true, true);
                                               schemaExport.Create(true, true);
                                           })
                  .BuildSessionFactory();
  
              // Add the ISessionFactory instance to the container
              container.Bind&lt;ISessionFactory&gt;().ToConstant(sessionFactory);
  
              // Configure a resolver method to be used for creating ISession objects
              container.Bind&lt;ISession&gt;().ToMethod(CreateSession);
  
              container.Bind&lt;ICurrentSessionContextAdapter&gt;().To&lt;CurrentSessionContextAdapter&gt;();
          }
  </code></pre>
  
  <p>Now i know what most of it is doing, but i am more interested to know more about this section;</p>
  
  <pre><code>.ExposeConfiguration(cfg =&gt;
                            {
                                var schemaExport = new SchemaExport(cfg);
                                schemaExport.Drop(true, true);
                                schemaExport.Create(true, true);
                             })
  </code></pre>
  
  <p>Idealy i expect <code>schemaExport.Drop(true, true);</code> to drop the database schema and <code>schemaExport.Create(true, true);</code> to recreate it. Now, is <code>SchemaExport</code> about the <a href="http://www.quackit.com/sql_server/sql_server_2008/tutorial/sql_server_database_schemas.cfm" rel="nofollow">Database Schemas</a> as we know it? I ask this because when i run my application with the mentioned configurations i get an error: </p>
  
  <p><code>There is already an object named 'AllUsers' in the database.</code> at <code>schemaExport.Create(true, true);</code></p>
  
  <p><code>AllUsers</code> is one of the database views i have as part of the schema</p>
  
  <p><strong>Appending Answer as requested</strong></p>
  
  <p>To fix the bug, i added <code>SchemaAction.None();</code> to UserMap as seen below.</p>
  
  <pre><code>public class UserMap : VersionedClassMap&lt;User&gt;
  {
      public UserMap()
      {
          Table("AllUsers"); //This is the database view which was causing the error
          SchemaAction.None(); // This was added to fix the porblem
  
          Id(x =&gt; x.UserId).CustomType&lt;Guid&gt;();            
          Map(x =&gt; x.Firstname).Not.Nullable();
          Map(x =&gt; x.Lastname).Not.Nullable();            
          Map(x =&gt; x.Email).Nullable();
          Map(x =&gt; x.Username).Not.Nullable();
      }
  }
  </code></pre>