private static ISessionFactory CreateSessionFactory(NhibernateConfig config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            return
                (Fluently.Configure()
                 .Database(MsSqlConfiguration.MsSql2008.ConnectionString(config.ConnectionString))
                 .FluentMappings(config)
                 .AutoMappings(config)
                 .Config(config)
                 .BuildSessionFactory());
        }
        private static FluentConfiguration Config(this FluentConfiguration configuration, NhibernateConfig config)
        {
            return(configuration.ExposeConfiguration(c =>
            {
                if (config.UpdateSchema)
                {
                    new SchemaUpdate(c).Execute(sql =>
                    {
                        if (!string.IsNullOrEmpty(config.ScriptsPath))
                        {
                            System.IO.File.AppendAllText(config.ScriptsPath, sql);
                        }
                    }, config.CommitUpdates);
                }

                //c.SetProperty("command_timeout", "300");
                //c.SetProperty("adonet.batch_size", "1");
            }));
        }
        private static FluentConfiguration FluentMappings(this FluentConfiguration configuration, NhibernateConfig config)
        {
            if (!config.AutoMap && config.MappingsAssembly != null)
            {
                return(configuration.Mappings(mapping => mapping.FluentMappings.AddFromAssembly(config.MappingsAssembly)));
            }

            return(configuration);
        }
        private static FluentConfiguration AutoMappings(this FluentConfiguration configuration, NhibernateConfig config)
        {
            if (config.AutoMap && config.MappingsAssembly != null)
            {
                var autoMap = AutoMap.Assembly(config.MappingsAssembly);

                if (config.AutoMappingFilter != null)
                {
                    autoMap = autoMap.Where(config.AutoMappingFilter);
                }

                if (config.UseNumericEnums)
                {
                    autoMap = autoMap.Conventions.Add <EnumConvention>();
                }

                return(configuration.Mappings(m => m.AutoMappings.Add(autoMap)));
            }

            return(configuration);
        }