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); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); optionsBuilder.EnableServiceProviderCaching(false); optionsBuilder.UseInMemoryDatabase("test"); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); optionsBuilder.UseInMemoryDatabase(nameof(TriggerContextFactoryTests)); optionsBuilder.EnableServiceProviderCaching(false); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder .EnableServiceProviderCaching(false) .UseJet( JetNorthwindTestStoreFactory.NorthwindConnectionString, TestEnvironment.DataAccessProviderFactory, b => b.ApplyConfiguration());
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { //optionsBuilder.UseSqlServer(); //用于设置是否启用缓存,暂时解决了可能出现的内存溢出的问题 optionsBuilder.EnableServiceProviderCaching(false); base.OnConfiguring(optionsBuilder); }
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); }
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); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { base.OnConfiguring(optionsBuilder); optionsBuilder.UseInMemoryDatabase("test"); optionsBuilder.EnableServiceProviderCaching(false); optionsBuilder.UseTriggers(triggerOptions => { triggerOptions.AddTrigger <TriggerStub <object> >(); }); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { Assert.Same(_options, optionsBuilder.Options); optionsBuilder .EnableServiceProviderCaching(false) .UseSqlServer(_connection, b => b.ApplyConfiguration()); Assert.NotSame(_options, optionsBuilder.Options); }
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 ")}"); }
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 }); } }
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>(); } }
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>(); } }
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"); }); }
protected override void OnConfiguring(DbContextOptionsBuilder options) => options .EnableServiceProviderCaching(false) .UseInMemoryDatabase(nameof(DbContextActivatorTest));
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder .EnableServiceProviderCaching(false) .UseSqlServer(b => b.ApplyConfiguration());
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.EnableServiceProviderCaching(false);
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.EnableSensitiveDataLogging(true); optionsBuilder.EnableServiceProviderCaching(false); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseInMemoryDatabase("myTestDb"); optionsBuilder.EnableServiceProviderCaching(true); base.OnConfiguring(optionsBuilder); }