コード例 #1
0
        public AbpProjectNameDbContext CreateDbContext(string[] args)
        {
            var builder       = new DbContextOptionsBuilder <AbpProjectNameDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            AbpProjectNameDbContextConfigurer.Configure(builder, configuration.GetConnectionString(AbpProjectNameConsts.ConnectionStringName));

            return(new AbpProjectNameDbContext(builder.Options));
        }
コード例 #2
0
 public override void PreInitialize()
 {
     if (!SkipDbContextRegistration)
     {
         Configuration.Modules.AbpEfCore().AddDbContext <AbpProjectNameDbContext>(configuration =>
         {
             AbpProjectNameDbContextConfigurer.Configure(configuration.DbContextOptions, configuration.ConnectionString);
         });
     }
 }
コード例 #3
0
        public AbpProjectNameDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder <AbpProjectNameDbContext>();

            /*
             * 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());

            AbpProjectNameDbContextConfigurer.Configure(builder, configuration.GetConnectionString(AbpProjectNameConsts.ConnectionStringName));

            return(new AbpProjectNameDbContext(builder.Options));
        }
 public override void PreInitialize()
 {
     if (!SkipDbContextRegistration)
     {
         Configuration.Modules.AbpEfCore().AddDbContext <AbpProjectNameDbContext>(options =>
         {
             if (options.ExistingConnection != null)
             {
                 AbpProjectNameDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
             }
             else
             {
                 AbpProjectNameDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
             }
         });
     }
 }