title: Fluently.Configure an NHibernate database from a config file?
body: <p>This question is similar to <a href="https://stackoverflow.com/questions/5109152/configuring-fluent-nhibernate-from-nhibernate-config-section">Configuring Fluent NHibernate from NHibernate config section</a> but I'm still trying to wrap my brain around this and the answer is not sufficient.</p>
  
  <p>I want to make a database-agnostic inventory management application (more as an experiment than anything else).  I want to use the Fluent automapper because it seems like a really cool idea if I could get it to work... keeps things nice and generic and kinda forces you to use a pattern.</p>
  
  <p>So, I make a helper class with a SessionFactory creator like so:</p>
  
  <pre><code>    private static ISessionFactory _SessionFactory;
  
      public static ISessionFactory SessionFactory {
          get {
              if (_SessionFactory == null) {
  
                  var config = new Configuration().Configure();
                  _SessionFactory = Fluently.Configure(config)
                      .Mappings (m =&gt; m.AutoMappings.Add (AutoMap.AssemblyOf&lt;Machine&gt; ()))
                      .BuildSessionFactory ();
              }
              return _SessionFactory;
          } 
      }
  
      public static ISession GetSession()
      {
          return SessionFactory.OpenSession();
      }
  </code></pre>
  
  <p>I make an app.config like so:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;configuration&gt;
      &lt;configSections&gt;
          &lt;section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /&gt;
      &lt;/configSections&gt;
      &lt;connectionStrings&gt;
          &lt;add name="NHDataModel" connectionString="Data Source=10.10.10.10;Integrated Security=SSPI;Database=Inventory;" /&gt;
      &lt;/connectionStrings&gt;
      &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
          &lt;session-factory&gt;
              &lt;property name="connection.provider"&gt;NHibernate.Connection.DriverConnectionProvider&lt;/property&gt;
              &lt;property name="connection.driver_class"&gt;NHibernate.Driver.SqlClientDriver&lt;/property&gt;
              &lt;property name="dialect"&gt;NHibernate.Dialect.MsSql2005Dialect&lt;/property&gt;
              &lt;property name="connection.connection_string_name"&gt;NHDataModel&lt;/property&gt;
              &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;/session-factory&gt;
      &lt;/hibernate-configuration&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>The error message I get when I try to generate a session to play with is as follows:</p>
  
  <pre><code>An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
  
    * Database was not configured through Database method.
  </code></pre>
  
  <p>There is no inner exception.</p>
  
  <p>I would think this works, but I would, of course, be wrong.  An examination of the config object shows that it has collected the property information in the app config, yet cannot seem to apply it to the fluent Database Method.  I have seen examples very similar to this all over the internet, though none matched exactly, so there's lots of room for stupid mistakes.</p>
  
  <p>I'm sure this is a simple thing, but I've been scratching my head over this for hours.  Any help would be greatly appreciated.  Nhibernate and FluentNhibernate are techs that I've never used before so this has been a steep learning curve.</p>