예제 #1
0
        public DbContextOptions CreateOptions(bool cached = false)
        {
            if (cached && _cachedOptionsBuilder != null)
            {
                return(_cachedOptionsBuilder.Options);
            }

            var optionBuilder = new DbContextOptionsBuilder();

            if (_settings["DatabaseProvider"] == null)
            {
                return(null);
            }

            switch (_settings["DatabaseProvider"])
            {
            case "SqlConnection":
                optionBuilder.UseSqlServer(_settings["ConnectionString"], ob =>
                {
                    // ob.UseRowNumberForPaging(true);
                });
                break;

            case "MySql":
                optionBuilder.UseMySql(
                    _settings["ConnectionString"],
                    ServerVersion.AutoDetect(_settings["ConnectionString"]),
                    ob =>
                {
                    ob.CharSetBehavior(CharSetBehavior.AppendToAllColumns);
                    ob.CharSet(CharSet.Utf8Mb4);
                });
                break;

            default:
                throw new ArgumentException("未知数据访问提供程序: " + _settings["DatabaseProvider"]);
            }

            optionBuilder.UseApplicationServiceProvider(_serviceProvider);

            if (cached)
            {
                optionBuilder.EnableServiceProviderCaching(true);
            }
            else
            {
                optionBuilder.EnableServiceProviderCaching(false);
            }

            if (cached && _cachedOptionsBuilder == null)
            {
                _cachedOptionsBuilder = optionBuilder;
            }

            return(optionBuilder.Options);
        }
예제 #2
0
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                base.OnConfiguring(optionsBuilder);

                optionsBuilder.EnableServiceProviderCaching(false);
                optionsBuilder.UseInMemoryDatabase("test");
            }
예제 #3
0
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                base.OnConfiguring(optionsBuilder);

                optionsBuilder.UseInMemoryDatabase(nameof(TriggerContextFactoryTests));
                optionsBuilder.EnableServiceProviderCaching(false);
            }
예제 #4
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 => optionsBuilder
 .EnableServiceProviderCaching(false)
 .UseJet(
     JetNorthwindTestStoreFactory.NorthwindConnectionString,
     TestEnvironment.DataAccessProviderFactory,
     b => b.ApplyConfiguration());
예제 #5
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            //optionsBuilder.UseSqlServer();

            //用于设置是否启用缓存,暂时解决了可能出现的内存溢出的问题
            optionsBuilder.EnableServiceProviderCaching(false);
            base.OnConfiguring(optionsBuilder);
        }
예제 #6
0
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseNpgsql("Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;");
        optionsBuilder.AddInterceptors(new SuppressCommandResultInterceptor());
        optionsBuilder.AddInterceptors(new SuppressConnectionInterceptor());
        optionsBuilder.EnableServiceProviderCaching();

        base.OnConfiguring(optionsBuilder);
    }
예제 #7
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            Assert.Same(_options, optionsBuilder.Options);

            optionsBuilder
            .EnableServiceProviderCaching(false)
            .UseSqlServer(SqlServerNorthwindTestStoreFactory.NorthwindConnectionString, b => b.ApplyConfiguration());

            Assert.NotSame(_options, optionsBuilder.Options);
        }
예제 #8
0
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                base.OnConfiguring(optionsBuilder);

                optionsBuilder.UseInMemoryDatabase("test");
                optionsBuilder.EnableServiceProviderCaching(false);
                optionsBuilder.UseTriggers(triggerOptions => {
                    triggerOptions.AddTrigger <TriggerStub <object> >();
                });
            }
예제 #9
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            Assert.Same(_options, optionsBuilder.Options);

            optionsBuilder
            .EnableServiceProviderCaching(false)
            .UseSqlServer(_connection, b => b.ApplyConfiguration());

            Assert.NotSame(_options, optionsBuilder.Options);
        }
예제 #10
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var currentDirectory = Environment.CurrentDirectory;
            var location         = currentDirectory.Substring(
                0, currentDirectory.IndexOf("CompiledModels", StringComparison.Ordinal) + "CompiledModels".Length);

            optionsBuilder
            //.UseModel(MyCompiledModels.BlogsContextModel.Instance)
            .EnableServiceProviderCaching(false)
            .UseSqlite(@$ "Data Source={Path.Combine(location, " compiled_model.db ")}");
        }
예제 #11
0
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                optionsBuilder
                .EnableServiceProviderCaching(false)
                .EnableSensitiveDataLogging()
                .UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=Scratch;ConnectRetryCount=0");
                //.UseSqlite("DataSource=test.db");

                if (!_quiet)
                {
                    optionsBuilder.LogTo(Console.WriteLine, new[] { RelationalEventId.CommandExecuted });
                }
            }
예제 #12
0
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseInternalServiceProvider(_serviceProvider);

            if (_databaseName == null)
            {
                optionsBuilder
                .EnableServiceProviderCaching(false)
                .UseInMemoryDatabase(Guid.NewGuid().ToString());
            }
            else
            {
                optionsBuilder.UseInMemoryDatabase(_databaseName);
            }
        }
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                base.OnConfiguring(optionsBuilder);

                optionsBuilder.UseInMemoryDatabase("test");
                optionsBuilder.EnableServiceProviderCaching(false);
                optionsBuilder.UseTriggers(triggerOptions => {
                    triggerOptions.AddTrigger(TriggerStub);
                });

                if (_stubService)
                {
                    optionsBuilder.ReplaceService <ITriggerService, TriggerServiceStub>();
                }
            }
예제 #14
0
 private static void EnableDevFeatures(DbContextOptionsBuilder builder, bool devMode)
 {
     if (devMode)
     {
         builder.EnableDetailedErrors();
         builder.EnableSensitiveDataLogging();
         builder.ConfigureWarnings(x => {
             x.Default(WarningBehavior.Log);
         });
     }
     else
     {
         builder.EnableServiceProviderCaching(true);
         builder.ConfigureWarnings(x => {
             x.Default(WarningBehavior.Ignore);
         });
     }
 }
            protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
            {
                base.OnConfiguring(optionsBuilder);

                optionsBuilder.ConfigureWarnings(warningOptions => {
                    warningOptions.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
                });

                optionsBuilder.UseInMemoryDatabase("test");
                optionsBuilder.EnableServiceProviderCaching(false);
                optionsBuilder.UseTriggers(triggerOptions => {
                    triggerOptions.AddTrigger(TriggerStub);
                });

                if (_stubService)
                {
                    optionsBuilder.ReplaceService <ITriggerService, TriggerServiceStub>();
                }
            }
예제 #16
0
        protected override void OnConfiguring(DbContextOptionsBuilder b)
        {
            base.OnConfiguring(b);

            if (string.IsNullOrEmpty(ConnectionString))
            {
                throw new NullReferenceException(nameof(ConnectionString));
            }

            b.EnableDetailedErrors();
            b.EnableSensitiveDataLogging();
            b.EnableServiceProviderCaching();

            b.UseSqlServer(ConnectionString,
                           b =>
            {
                b.EnableRetryOnFailure();
                b.MigrationsAssembly("CalendarUI.Presentation");
            });
        }
예제 #17
0
 protected override void OnConfiguring(DbContextOptionsBuilder options)
 => options
 .EnableServiceProviderCaching(false)
 .UseInMemoryDatabase(nameof(DbContextActivatorTest));
예제 #18
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 => optionsBuilder
 .EnableServiceProviderCaching(false)
 .UseSqlServer(b => b.ApplyConfiguration());
예제 #19
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 => optionsBuilder.EnableServiceProviderCaching(false);
예제 #20
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.EnableSensitiveDataLogging(true);
     optionsBuilder.EnableServiceProviderCaching(false);
 }
예제 #21
0
 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
     optionsBuilder.UseInMemoryDatabase("myTestDb");
     optionsBuilder.EnableServiceProviderCaching(true);
     base.OnConfiguring(optionsBuilder);
 }