示例#1
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile($"appsettings.json", optional: false, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true)
                          .AddEnvironmentVariables();

            Configuration = builder.Build();
            _config       = Configuration;
            var connectionString   = Configuration.GetConnectionString("DefaultConnection");
            var migrationNamespace = Configuration["ConfigSettings:MigrationNamespace"];

            BaseRepository.ConnectionString = connectionString;
            MigrationHelper.CreateDbIfNoneExists(connectionString);
            ViewRepository viewRepository = new ViewRepository(new NpgsqlConnection(connectionString));

            viewRepository.DropViews();
            MigrationHelper.MigrateUp(connectionString, migrationNamespace);
            viewRepository.CreateViews();
            MapperHelper.MapAllEntities();
        }