Ejemplo n.º 1
0
        static NHibernateConfigurator()
        {
            var sqlitePersistenceConfigurerProvider = new SqlitePersistenceConfigurerProvider();

#if DEBUG
            FluentConfigurationSerializer.IsEnabled = false;
#endif
            var configurationProvider = new FluentConfigurationProvider(sqlitePersistenceConfigurerProvider, new AssemblyLocator());

            _configuration = configurationProvider.Configure().GetEnumerator().Current;

            _configuration = _configuration.DataBaseIntegration(db => db.ConnectionProvider <TestConnectionProvider> ());
            _configuration.SetProperty(Environment.CurrentSessionContextClass, "thread_static");

            var props = _configuration.Properties;
            if (props.ContainsKey(Environment.ConnectionStringName))
            {
                props.Remove(Environment.ConnectionStringName);
            }

            // This line is only for TFS integration build MSTest runner
            ForceLoadingAssembliesForMsTestRunner();

            _sessionFactory = _configuration.BuildSessionFactory();
        }
Ejemplo n.º 2
0
        private void InitNHibernate()
        {
            var mapper = new ModelMapper();

            mapper.AddMappings(typeof(ProductoMap).Assembly.ExportedTypes);
            HbmMapping domainMapping = mapper.CompileMappingForAllExplicitlyAddedEntities();

            string connectionString = _appConfiguration.GetConnectionString("DefaultConnection");

            var configuration = new NHibernate.Cfg.Configuration();

            configuration.DataBaseIntegration(c =>
            {
                c.Dialect <NHibernate.Dialect.MySQLDialect>();
                c.ConnectionString = connectionString;
                //c.KeywordsAutoImport = Hbm2DDLKeyWords.AutoQuote;
                //c.SchemaAction = SchemaAutoAction.Validate;
                #if (DEBUG)
                c.LogFormattedSql = true;
                c.LogSqlInConsole = true;
                #endif
            });

            configuration.AddMapping(domainMapping);

            var sessionFactory = configuration.BuildSessionFactory();

            this.DbSession = sessionFactory.OpenSession();

            #if (DEBUG)
            NHibernateLogger.SetLoggersFactory(new NHLoggerFactory(this.Log));
            #endif
        }
Ejemplo n.º 3
0
        public static ISession OpenSession()
        {
            var cfg = new NHibernate.Cfg.Configuration();

            cfg.DataBaseIntegration(x =>
            {
                x.ConnectionString = @"Data Source=localhost;Initial Catalog=Academics;Integrated Security=true;MultipleActiveResultSets=true;";
                x.Driver <SqlClientDriver>();
                x.Dialect <MsSql2012Dialect>();
                x.LogSqlInConsole = true;
            });
            cfg.AddAssembly(Assembly.GetExecutingAssembly());
            var      sessionFactory = cfg.BuildSessionFactory();
            ISession session        = sessionFactory.OpenSession();

            return(session);
        }
Ejemplo n.º 4
0
        static NHibernateConfigurator()
        {
            var sqlitePersistenceConfigurerProvider = new SqlitePersistenceConfigurerProvider ();
            #if DEBUG
            FluentConfigurationSerializer.IsEnabled = false;
            #endif
            var configurationProvider = new FluentConfigurationProvider ( sqlitePersistenceConfigurerProvider , new AssemblyLocator());

            _configuration = configurationProvider.Configure ().GetEnumerator ().Current;

            _configuration = _configuration.DataBaseIntegration ( db => db.ConnectionProvider<TestConnectionProvider> () );
            _configuration.SetProperty ( Environment.CurrentSessionContextClass, "thread_static" );

            var props = _configuration.Properties;
            if ( props.ContainsKey ( Environment.ConnectionStringName ) )
                props.Remove ( Environment.ConnectionStringName );

            // This line is only for TFS integration build MSTest runner
            ForceLoadingAssembliesForMsTestRunner();

            _sessionFactory = _configuration.BuildSessionFactory ();
        }