Ejemplo n.º 1
0
        public Configuration BuildConfiguration(SessionFactoryParameters parameters)
        {
            var database = GetPersistenceConfigurer(parameters.CreateDatabase);
            var persistenceModel = CreatePersistenceModel(parameters.RecordDescriptors.ToList());

            //foreach (var recordType in parameters.RecordDescriptors.Select(x => x.Type).Distinct())
            //{
            //    persistenceModel.Override(recordType);
            //}

            var config = Fluently.Configure();

            parameters.Configurers.Invoke(c => c.Created(config, persistenceModel), Logger);

            config = config.Database(database)
                           .Mappings(m =>
                           {
                               m.AutoMappings.Add(persistenceModel);
                           })
                           .ExposeConfiguration(cfg =>
                           {
                               cfg
                                    .SetProperty(NHibernate.Cfg.Environment.FormatSql, Boolean.FalseString)
                                    .SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, Boolean.FalseString)
                                    .SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, Hbm2DDLKeyWords.None.ToString())
                                    .SetProperty(NHibernate.Cfg.Environment.PropertyBytecodeProvider, "lcg")
                                    .SetProperty(NHibernate.Cfg.Environment.PropertyUseReflectionOptimizer, Boolean.TrueString)
                                    .SetProperty(NHibernate.Cfg.Environment.QueryStartupChecking, Boolean.FalseString)
                                    .SetProperty(NHibernate.Cfg.Environment.ShowSql, Boolean.FalseString)
                                    .SetProperty(NHibernate.Cfg.Environment.StatementFetchSize, "100")
                                    .SetProperty(NHibernate.Cfg.Environment.UseProxyValidator, Boolean.FalseString)
                                    .SetProperty(NHibernate.Cfg.Environment.UseSqlComments, Boolean.FalseString)
                                    .SetProperty(NHibernate.Cfg.Environment.WrapResultSets, Boolean.TrueString);

                               cfg.EventListeners.LoadEventListeners = new ILoadEventListener[] { new OrchardLoadEventListener() };
                               cfg.EventListeners.PostLoadEventListeners = new IPostLoadEventListener[0];
                               cfg.EventListeners.PreLoadEventListeners = new IPreLoadEventListener[0];

                               // don't enable PrepareSql by default as it breaks on SqlCe
                               // this can be done per driver by overriding AlterConfiguration
                               AlterConfiguration(cfg);

                               parameters.Configurers.Invoke(c => c.Building(cfg), Logger);

                           })
                           ;

            parameters.Configurers.Invoke(c => c.Prepared(config), Logger);

            return config.BuildConfiguration();
        }
Ejemplo n.º 2
0
        public Configuration BuildConfiguration(SessionFactoryParameters parameters)
        {
            var database         = GetPersistenceConfigurer(parameters.CreateDatabase);
            var persistenceModel = CreatePersistenceModel(parameters.RecordDescriptors.ToList());

            //foreach (var recordType in parameters.RecordDescriptors.Select(x => x.Type).Distinct())
            //{
            //    persistenceModel.Override(recordType);
            //}

            var config = Fluently.Configure();

            parameters.Configurers.Invoke(c => c.Created(config, persistenceModel), Logger);

            config = config.Database(database)
                     .Mappings(m =>
            {
                m.AutoMappings.Add(persistenceModel);
            })
                     .ExposeConfiguration(cfg =>
            {
                cfg
                .SetProperty(NHibernate.Cfg.Environment.FormatSql, Boolean.FalseString)
                .SetProperty(NHibernate.Cfg.Environment.GenerateStatistics, Boolean.FalseString)
                .SetProperty(NHibernate.Cfg.Environment.Hbm2ddlKeyWords, Hbm2DDLKeyWords.None.ToString())
                .SetProperty(NHibernate.Cfg.Environment.PropertyBytecodeProvider, "lcg")
                .SetProperty(NHibernate.Cfg.Environment.PropertyUseReflectionOptimizer, Boolean.TrueString)
                .SetProperty(NHibernate.Cfg.Environment.QueryStartupChecking, Boolean.FalseString)
                .SetProperty(NHibernate.Cfg.Environment.ShowSql, Boolean.FalseString)
                .SetProperty(NHibernate.Cfg.Environment.StatementFetchSize, "100")
                .SetProperty(NHibernate.Cfg.Environment.UseProxyValidator, Boolean.FalseString)
                .SetProperty(NHibernate.Cfg.Environment.UseSqlComments, Boolean.FalseString)
                .SetProperty(NHibernate.Cfg.Environment.WrapResultSets, Boolean.TrueString);

                cfg.EventListeners.LoadEventListeners     = new ILoadEventListener[] { new OrchardLoadEventListener() };
                cfg.EventListeners.PostLoadEventListeners = new IPostLoadEventListener[0];
                cfg.EventListeners.PreLoadEventListeners  = new IPreLoadEventListener[0];

                // don't enable PrepareSql by default as it breaks on SqlCe
                // this can be done per driver by overriding AlterConfiguration
                AlterConfiguration(cfg);

                parameters.Configurers.Invoke(c => c.Building(cfg), Logger);
            })
            ;

            parameters.Configurers.Invoke(c => c.Prepared(config), Logger);

            return(config.BuildConfiguration());
        }