Пример #1
0
        public NHibernateHelper(Microsoft.AspNetCore.Http.IHttpContextAccessor httpContextAccessor,
                                IConnections connections)
        {
            this.httpContextAccessor = httpContextAccessor;

            string connectionString = connections.GetDefaultConnectionString();

            FluentConfiguration fluentConfiguration = Fluently.Configure();

            fluentConfiguration = fluentConfiguration.Database(OracleClientConfiguration.Oracle10
                                                               .ConnectionString(connectionString));

            _sessionFactory = fluentConfiguration
                              .Mappings(m => m.FluentMappings.AddFromAssemblyOf <Mappings>())
                              .Mappings(m => m.FluentMappings.AddFromAssemblyOf <Program>())
                              .ExposeConfiguration(x => x.SetProperty("hbm2ddl.keywords", "auto-quote"))
                              .BuildSessionFactory();
        }
Пример #2
0
        /// <summary>
        /// Обновить структуру БД до последней версии.
        /// Использует подключение в БД по умолчанию.
        /// </summary>
        public void UpdateDatabase()
        {
            string connectionString = connections.GetDefaultConnectionString();

            var serviceCollection = new ServiceCollection()

                                    .AddFluentMigratorCore()
                                    .ConfigureRunner(rb => {
                rb.AddOracleManaged();

                // задать подключение к БД
                rb.WithGlobalConnectionString(connectionString)
                // Сборка в которой искать миграции
                .ScanIn(typeof(Program).Assembly).For.Migrations();
            });

            var serviceProvider = serviceCollection.BuildServiceProvider(false);

            using (var scope = serviceProvider.CreateScope())
            {
                var runner = scope.ServiceProvider.GetRequiredService <IMigrationRunner>();
                runner.MigrateUp();
            }
        }