Configure() public method

public Configure ( NHibernate.Cfg.Configuration cfg ) : void
cfg NHibernate.Cfg.Configuration
return void
Exemplo n.º 1
0
        public static void MyClassInitialize(TestContext testContext)
        {
            try {
                IPersistenceConfigurer persistenceConfigurer = MySQLConfiguration.Standard.ConnectionString(c => c.Is("Server=localhost;Database=basicproject;User ID=root;Password=1234")).ShowSql();
                // initialize nhibernate with persistance configurer properties
                Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration());

                // add mappings definition to nhibernate configuration
                var persistenceModel = new PersistenceModel();
                persistenceModel.AddMappingsFromAssembly(Assembly.Load("BasicProject.NHibernateInfra.Implementation"));
                persistenceModel.Configure(cfg);
                // set session factory field which is to be used in tests
                _sessionFactory = cfg.BuildSessionFactory();
            } catch (ReflectionTypeLoadException ex) {
                StringBuilder sb = new StringBuilder();
                foreach (Exception exSub in ex.LoaderExceptions) {
                    sb.AppendLine(exSub.Message);
                    if (exSub is FileNotFoundException) {
                        FileNotFoundException exFileNotFound = exSub as FileNotFoundException;
                        if (!string.IsNullOrEmpty(exFileNotFound.FusionLog)) {
                            sb.AppendLine("Fusion Log:");
                            sb.AppendLine(exFileNotFound.FusionLog);
                        }
                    }
                    sb.AppendLine();
                }
                string errorMessage = sb.ToString();
                //Display or log the error based on your application.
            }
        }
Exemplo n.º 2
0
        public static Configuration AddMappingsFromAssembly(this Configuration configuration, Assembly assembly)
        {
            var models = new PersistenceModel();
            models.AddMappingsFromAssembly(assembly);
            models.Configure(configuration);

            return configuration;
        }
Exemplo n.º 3
0
        public static Configuration AddMappingsFromAssembly(this Configuration configuration, Assembly assembly)
        {
            var models = new PersistenceModel();

            models.AddMappingsFromAssembly(assembly);
            models.Configure(configuration);

            return(configuration);
        }
        protected void Initialize(Configuration nhibernateConfig, PersistenceModel model)
        {
            if( model == null ) throw new ArgumentNullException("model", "Model cannot be null");

            Configuration = nhibernateConfig;

            model.Configure(Configuration);

            SessionFactory = Configuration.BuildSessionFactory();
            dialect = Dialect.GetDialect(Configuration.Properties);
        }
Exemplo n.º 5
0
        protected void Initialize(Configuration nhibernateConfig, PersistenceModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model", "Model cannot be null");
            }

            Configuration = nhibernateConfig;

            model.Configure(Configuration);

            SessionFactory = Configuration.BuildSessionFactory();
            dialect        = Dialect.GetDialect(Configuration.Properties);
        }
        public FluentConfigurer ExportHbmMappings()
        {
            if (!Directory.Exists(ExportDirectory))
            {
                Directory.CreateDirectory(ExportDirectory);
            }

            var persistenceModel = new PersistenceModel();
            persistenceModel.AddMappingsFromAssembly(Assembly.GetAssembly(typeof(FluentConfigurer)));
            persistenceModel.Configure(Configuration);
            persistenceModel.WriteMappingsTo(ExportDirectory);

            return this;
        }
Exemplo n.º 7
0
        private NHibernate.Cfg.Configuration buildNewConfig()
        {
            var config = new NHibernate.Cfg.Configuration();
            buildConfig().ConfigureProperties(config.SetProperty("config-source", this.GetType().FullName));

            config.EventListeners.PreInsertEventListeners = new NHibernate.Event.IPreInsertEventListener[] { new TimeStampEventListener() };
            config.EventListeners.PreUpdateEventListeners = new NHibernate.Event.IPreUpdateEventListener[] { new TimeStampEventListener() };

            var model = new PersistenceModel();
            modifyPersistenceModel(model);
            model.Configure(config);

            return addConfig(config);
        }
Exemplo n.º 8
0
        public MySessionSource(IDictionary<string, string> properties, PersistenceModel model)
        {
            if(model == null) throw new ArgumentException("Model cannot be null!");

            _configuration = new Configuration();
            if (properties == null)
                _configuration.Configure();
            else
                _configuration.AddProperties(properties);

            Model = model;
            model.Configure(_configuration);

            _sessionFactory = _configuration.BuildSessionFactory();
        }
Exemplo n.º 9
0
        private static void buildModel()
        {
            // initialize persistance configurer
            IPersistenceConfigurer persistenceConfigurer = getPersistenceConfigurer();
            // initialize nhibernate with persistance configurer properties
            cfg = persistenceConfigurer.ConfigureProperties(new Configuration());
            // add mappings definition to nhibernate configuration
            var persistenceModel = new PersistenceModel();
            persistenceModel.addMappingsFromAssembly(typeof(ModelBuilder).Assembly);
            persistenceModel.Conventions.GetPrimaryKeyName = x => x.Name;
            persistenceModel.Conventions.GetForeignKeyName = x => x.Name;
            persistenceModel.Configure(cfg);

            //Mix mode, this line allows us to append config settings to our configuration
            //instance from .config files (web.config,app.config)
            // or any other "traditional" (xml based) approach.
            //NOTE: If you are going to go with full Fluent configuration, you should remove the line below
            cfg.Configure();
        }
Exemplo n.º 10
0
        private ISessionFactory CreateConfiguration()
        {
            IPersistenceConfigurer persistenceConfigurer =
                MsSqlConfiguration.MsSql2008.ConnectionString
                        (c => c.FromConnectionStringWithKey("RepositoryPatternDemo"));

            Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration());

            var persistenceModel = new PersistenceModel();
            var assembly = typeof(BlogPostMap).Assembly;
            persistenceModel.AddMappingsFromAssembly(assembly);
            persistenceModel.Configure(cfg);
            return cfg.BuildSessionFactory();
        }
Exemplo n.º 11
0
        private void InitSessionFactory()
        {
            IPersistenceConfigurer persistenceConfigurer = MsSqlConfiguration
                .MsSql2005
                .ConnectionString(c => c.FromConnectionStringWithKey("CxRomosConnStr"))
                .UseReflectionOptimizer().ShowSql();

            Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration());
            var persistenceModel = new PersistenceModel();
            persistenceModel.AddMappingsFromAssembly(Assembly.Load("CxRomos.Core"));
            persistenceModel.Configure(cfg);
            _sessionFactory = cfg.BuildSessionFactory();
        }
Exemplo n.º 12
0
        private void InitSessionFactory()
        {
            IPersistenceConfigurer persistenceConfigurer = MsSqlConfiguration
               .MsSql2005
               .ConnectionString(c => c.FromConnectionStringWithKey("TimeTracker.Reporting.Properties.Settings.TimeTrackerConnStr"));

            Configuration cfg = persistenceConfigurer.ConfigureProperties(new Configuration());
            var persistenceModel = new PersistenceModel();
            persistenceModel.AddMappingsFromAssembly(Assembly.Load("TimeTracker.Core"));
            persistenceModel.Configure(cfg);
            sessionFactory = cfg.BuildSessionFactory();
        }