Fluent NHibernate "Database was not configured through Database method."
<p>i'm starting with Fluent.NHibernate for my C# web probject that already uses NHibernate correctly and now i want to migrate to Fluent.</p>

<p>When i try to doing a config request i receive the error:</p>

<blockquote>
  <p>An invalid or incomplete configuration was used while creating a
  SessionFactory. Check PotentialReasons collection, and InnerException
  for more detail.</p>
  
  <ul>
  <li>Database was not configured through Database method.</li>
  </ul>
</blockquote>

<p>into PotentialReason property i see:</p>

<blockquote>
  <p>Database was not configured through Database method.</p>
</blockquote>

<p>into the InnerException into InnerException (xD) i see:</p>

<blockquote>
  <p>composite-id class must override Equals(): it.quasar.core.libraries.entities.Config</p>
</blockquote>

<p>but when i change from Fluent to NHibernate (using classic hbm file and without changing the Config class), i don't see any problems... so the problem occurs when i using Fluent library.</p>

<p>The error appears when the code try to execute this instruction:</p>

<pre><code>this._sessionFactory = this._configuration
                .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;TIdentifier&gt;())
                .BuildSessionFactory();
</code></pre>

<p>At the moment I have tried to migrate just one entity (Config.cs), this is my entity:</p>

<pre><code>public class ConfigKey : BaseKey
{
    public virtual string id { get; set; }

    public ConfigKey() : base()
    {
        if(this.userId == null)
        {
            this.userId = "SYSTEM";
        }
    }

    #region OVERRIDES
    public override bool Equals(object obj)
    {
        if(obj != null)
        {
            ConfigKey _key = obj as ConfigKey;
            if(_key == null)
            {
                return false;
            }

            if(_key.id == this.id &amp;&amp; _key.applicationId == this.applicationId &amp;&amp; _key.id == this.id)
            {
                return true;
            }
        }

        return false;
    }

    public override int GetHashCode()
    {
        return (this.id.ToString() + "|" + this.applicationId.ToString() + "|" + this.id)
            .GetHashCode();
    }
    #endregion
}

public class Config : BaseEntity&lt;ConfigKey&gt;
{
    public virtual string value { get; set; }
    public virtual string description { get; set; }

    #region CONSTRUCTORS
    public Config() { }

    public Config(ConfigKey key)
    {
        this.key = key;
    }
    #endregion
}

public abstract class BaseKey
{
    public virtual Guid applicationId { get; set; }
    public virtual string userId { get; set; }

    public virtual bool isNew
    {
        get
        {
            bool test = false;

            Dictionary&lt;string, ObjectDefinition&gt; transposed = this.Transpose();
            foreach (KeyValuePair&lt;string, ObjectDefinition&gt; property in transposed)
            {
                if (property.Value.Value == null)
                {
                    test = true;
                    break;
                }
                else if (property.Value.Default != null &amp;&amp; (property.Value.Value.ToString() == property.Value.Default.ToString()))
                {
                    test = true;
                    break;
                }
            }

            return test;
        }
    }

    public BaseKey()
    {
        this.applicationId = BaseContext.getContext.applicationId;

        try
        {
            //if exists a user context, take the user id
            this.userId = BaseContext.getContext.user.key.id;
        }
        catch
        {
            //else user id is not setted
            this.userId = null;
        }
    }

    #region OVERRIDES
    public override bool Equals(object obj)
    {
        if (obj != null)
        {
            BaseKey _key = obj as BaseKey;
            if (_key == null)
            {
                return false;
            }

            if (_key.applicationId == this.applicationId &amp;&amp; _key.userId == this.userId)
            {
                return true;
            }
        }

        return false;
    }

    public override int GetHashCode()
    {
        return (this.applicationId.ToString() + "|" + this.userId)
            .GetHashCode();
    }
    #endregion
}
</code></pre>

<p>and the map class is the following (Config and ConfigMap are into the same namespace and into the same assembly):</p>

<pre><code>public class ConfigMap : ClassMap&lt;Config&gt;
{
    public ConfigMap()
    {
        Schema("dbo");
        Table("CONFIG");

        CompositeId()
            .KeyProperty(x =&gt; x.key.applicationId, "APPLICATION_ID")
            .KeyProperty(x =&gt; x.key.userId, "USER_ID")
            .KeyProperty(x =&gt; x.key.id, "ID");

        Map(x =&gt; x.description, "DESCRIPTION");
        Map(x =&gt; x.value, "VALUE");
    }
}
</code></pre>

<p>and this is the SessionFactory (i used it for classical NHibernate, i have created this new one in another namespace for Fluent):</p>

<pre><code>public class NHibernateHelper&lt;TIdentifier&gt; where TIdentifier : class
{
    ISessionFactory _sessionFactory;
    FluentConfiguration _configuration;

    private ISessionFactory SessionFactory
    {
        get
        {
            if (this._sessionFactory == null)
            {
                if(this._configuration == null)
                {
                    this._configuration = Fluently.Configure();
                }

                this._sessionFactory = this._configuration
                    .Mappings(m =&gt; m.FluentMappings.AddFromAssemblyOf&lt;TIdentifier&gt;())
                    .BuildSessionFactory();
            }

            return this._sessionFactory;
        }
    }
...
}
</code></pre>

<p>into my web.config i have left the same that i used for NHibernate:</p>

<pre><code>  &lt;!-- NHibernate configuration --&gt;
  &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"&gt;
    &lt;session-factory name="it.quasar.NHibernate"&gt;
      &lt;property name="connection.driver_class"&gt;NHibernate.Driver.SqlClientDriver&lt;/property&gt;
      &lt;!--roperty name="connection.driver_class"&gt;NHibernate.Driver.OleDbDriver&lt;/property--&gt;
      &lt;property name="dialect"&gt;NHibernate.Dialect.MsSql2008Dialect&lt;/property&gt;
      &lt;property name="connection.connection_string_name"&gt;lollo&lt;/property&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
</code></pre>

<p>I need your help :)
What's wrong in my code? What can i do to correct my code?</p>

<p>Thanks a lot to everybody! :)</p>

<p>Lorenzo</p>