private PostgreSQLConfiguration GetPostgresConfiguration(NhibernateSettings nhibernateSettings)
        {
            PostgreSQLConfiguration config =
                PostgreSQLConfiguration.PostgreSQL82
                .ConnectionString(nhibernateSettings.ConnectionString)
                .DefaultSchema(nhibernateSettings.DBSchema);

            if (nhibernateSettings.ShowSQL)
            {
                config.ShowSql();
            }
            return(config);
        }
        private MySQLConfiguration GetMysqlConfiguration(NhibernateSettings nhibernateSettings)
        {
            MySQLConfiguration config =
                MySQLConfiguration.Standard
                .ConnectionString(nhibernateSettings.ConnectionString)
                .DefaultSchema(nhibernateSettings.DBSchema);

            if (nhibernateSettings.ShowSQL)
            {
                config.ShowSql();
            }
            return(config);
        }
        private static SQLiteConfiguration GetSqlLiteConfiguration(NhibernateSettings nhibernateSettings)
        {
            SQLiteConfiguration config =
                SQLiteConfiguration.Standard
                .ConnectionString(nhibernateSettings.ConnectionString)
                .DefaultSchema(nhibernateSettings.DBSchema);

            if (nhibernateSettings.ShowSQL)
            {
                config.ShowSql();
            }
            return(config);
        }
        private IPersistenceConfigurer GetPersistenceConfigurer(NhibernateSettings nhibernateSettings)
        {
            IPersistenceConfigurer config;

            switch (nhibernateSettings.DbType)
            {
            case DbType.Postgres:
                config = GetPostgresConfiguration(nhibernateSettings);
                break;

            case DbType.SqlLite:
                config = GetSqlLiteConfiguration(nhibernateSettings);
                break;

            case DbType.Mysql:
                config = GetMysqlConfiguration(nhibernateSettings);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(config);
        }
        private Configuration BuildConfiguration(NhibernateSettings settings, Assembly assemblyEntities)
        {
            var config =
                Fluently.Configure()
                .Database(GetPersistenceConfigurer(settings))
                .Mappings(map => map.FluentMappings.AddFromAssembly(assemblyEntities));

            if (settings.ReCreateDatabase)
            {
                config.ExposeConfiguration(GetCreateSchema);
            }
            else
            {
                config.ExposeConfiguration(GetSchema);
            }
            Configuration buildConfig = config.BuildConfiguration();

            if (buildConfig == null)
            {
                throw new Exception("Cannot build NHibernate configuration");
            }

            return(buildConfig);
        }