コード例 #1
0
        public NewTemplateDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <NewTemplateDbContext>();

            /*
             * You can provide an environmentName parameter to the AppConfigurations.Get method.
             * In this case, AppConfigurations will try to read appsettings.{environmentName}.json.
             * Use Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") method or from string[] args to get environment if necessary.
             * https://docs.microsoft.com/en-us/ef/core/cli/dbcontext-creation?tabs=dotnet-core-cli#args
             */
            var configuration = AppConfigurations.Get(
                WebContentDirectoryFinder.CalculateContentRootFolder(),
                addUserSecrets: true
                );

            NewTemplateDbContextConfigurer.Configure(builder, configuration.GetConnectionString(NewTemplateConsts.ConnectionStringName));

            return(new NewTemplateDbContext(builder.Options));
        }
コード例 #2
0
        public override void PreInitialize()
        {
            if (!SkipDbContextRegistration)
            {
                Configuration.Modules.AbpEfCore().AddDbContext <NewTemplateDbContext>(options =>
                {
                    if (options.ExistingConnection != null)
                    {
                        NewTemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
                    }
                    else
                    {
                        NewTemplateDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
                    }
                });
            }

            // Set this setting to true for enabling entity history.
            Configuration.EntityHistory.IsEnabled = false;

            // Uncomment below line to write change logs for the entities below:
            // Configuration.EntityHistory.Selectors.Add("NewTemplateEntities", EntityHistoryHelper.TrackedTypes);
            // Configuration.CustomConfigProviders.Add(new EntityHistoryConfigProvider(Configuration));
        }