title: Generate database with Nhibernate using Fluent NHibernate
body: <p>I'm trying to use (new with) Fluent NHibernate (trying to switch from XML mapping file to FNH). With the code below, I generated the database, I'm trying to find the same solution but with FNH (I'd like still use hibernate.cfg.xml) :</p>
  
  <pre><code>public void CreateDatabase()
  {
      NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
  
      cfg.Configure();
      SchemaMetadataUpdater.QuoteTableAndColumns(cfg);
      NHibernate.Tool.hbm2ddl.SchemaExport schema = new NHibernate.Tool.hbm2ddl.SchemaExport(cfg);
  
      schema.Create(false, true);
  }
  
  
  namespace MyTestApplication.Entities
  {
      public class Person
      {
          public virtual int Id { get; set; }
          public virtual string FirstName { get; set; }
          public virtual string LastName { get; set; }
      }
  }
  
  namespace MyTestApplication.Data.Mapping
  {
      public class PersonMapping : ClassMap&lt;Person&gt;
      {
          public PersonMapping()
          {
              Id(x =&gt; x.Id);
              Map(x =&gt; x.FirstName);
              Map(x =&gt; x.LastName);      
          }
      }
  }
  </code></pre>
  
  <p><strong>Solution</strong></p>
  
  <p>Finally, I use this (Thanks to Marco) : </p>
  
  <pre><code> public void CreationDB()
      {
          FluentConfiguration config = Fluently.Configure()
              .Database(MsSqlConfiguration.MsSql2008.ConnectionString("......"))
              .Mappings(
                  m =&gt; m.FluentMappings.Add(typeof(MyTestApplication.Data.Mapping.PersonMapping)
              ));
  
          config.ExposeConfiguration(
                    c =&gt; new SchemaExport(c).Execute(true, true, false))
               .BuildConfiguration();
      }
  </code></pre>