public GlobalStandardsContext(DbContextOptions <GlobalStandardsContext> options) : base(options) { if (options.FindExtension <SqlServerOptionsExtension>() != null) { ConnectionStr = options.FindExtension <SqlServerOptionsExtension>().ConnectionString; } }
public EmployeeDbContext(DbContextOptions <EmployeeDbContext> options) : base(options) { if (s_migrated[0]) { return; } lock (s_migrated) { if (s_migrated[0] == false) { var memoryOptions = options.FindExtension <InMemoryOptionsExtension>(); if (memoryOptions == null) { var sqlOptions = options.FindExtension <SqlServerOptionsExtension>(); if (sqlOptions != null) { Console.WriteLine($"EmployeeDbContext of connection string be '{sqlOptions.ConnectionString}'"); this.Database.Migrate(); } } s_migrated[0] = true; } } }
public MigrationHistoryContext(DbContextOptions <MigrationHistoryContext> options) : base(options) { if (options.FindExtension <SqlServerOptionsExtension>() != null) { ConnectionStr = options.FindExtension <SqlServerOptionsExtension>().ConnectionString; } }
// can only have a single option per instance. //private bool UseDefaultBuilder { get; set; } = true; public MeterDevicesDbContext(DbContextOptions <MeterDevicesDbContext> options) : base(options) { if (options.FindExtension <SqlServerOptionsExtension>() != null) { ConnectionStr = options.FindExtension <SqlServerOptionsExtension>().ConnectionString; } }
public NuEmailsContext(DbContextOptions <NuEmailsContext> options) : base(options) { if (options.FindExtension <SqlServerOptionsExtension>() != null) { ConnectionStr = options.FindExtension <SqlServerOptionsExtension>().ConnectionString; } }
public EmployeeDbContext(DbContextOptions <EmployeeDbContext> options) : base(options) { if (s_migrated[0]) { return; } lock (s_migrated) { if (s_migrated[0] == false) { var memoryOptions = options.FindExtension <InMemoryOptionsExtension>(); if (memoryOptions == null) { var sqliteOptionsExtension = options.FindExtension <SqliteOptionsExtension>(); if (sqliteOptionsExtension != null) { Console.WriteLine($"EmployeeDbContext 的連線字串為:{sqliteOptionsExtension.ConnectionString},執行 Migration"); } this.Database.Migrate(); } s_migrated[0] = true; } } }
protected DbContextAccessorBase(DbContextOptions options) : base(options) { var extension = options.FindExtension <CoreOptionsExtension>(); var relationalExtension = RelationalOptionsExtension.Extract(options); MemoryCache = extension.MemoryCache; var dataBuilder = MemoryCache.GetDataBuilder(); if (dataBuilder.IsNull()) { throw new InvalidOperationException($"You need to register to builder.{nameof(AccessorDataBuilderExtensions.AddAccessor)}()."); } Dependency = dataBuilder.Dependency as DataBuilderDependency; if (Dependency.Options.DefaultTenant.IsNull()) { throw new InvalidOperationException($"The data builder dependency '{Dependency}' options default tenant is null."); } // Database.GetDbConnection().ConnectionString 的信息不一定完整(比如密码) if (relationalExtension.ConnectionString.IsEmpty()) { throw new InvalidOperationException($"The relational options extension '{relationalExtension}' connection string is empty."); } CurrentTenant = Dependency.Options.DefaultTenant; CurrentConnectionString = relationalExtension.ConnectionString; Dependency.Options.PostAccessorInitializedAction?.Invoke(this); }
public CoreDbContext(DbContextOptions options) : base(options) { var serviceProvider = options.FindExtension <CoreOptionsExtension>().ApplicationServiceProvider; MessagePublisher = serviceProvider.GetService <IMessagePublisher>(); }
public static DbContextOptions CreateOptions(this DbContextOptionsBuilder optionsBuilder, DbContextOptions options) { DbContextOptions contextOptions = optionsBuilder.Options; foreach (IDbContextOptionsExtension extension in options.Extensions) { if (extension is CoreOptionsExtension coreOptionsExtension) { CoreOptionsExtension?newCoreOptions = contextOptions.FindExtension <CoreOptionsExtension>(); if (newCoreOptions == null) { contextOptions = contextOptions.WithExtension(coreOptionsExtension); } else { if (coreOptionsExtension.ReplacedServices != null) { foreach (KeyValuePair <Type, Type> replacedService in coreOptionsExtension.ReplacedServices) { newCoreOptions = newCoreOptions.WithReplacedService(replacedService.Key, replacedService.Value); } contextOptions = contextOptions.WithExtension(newCoreOptions); } } } else { var withExtensionFunc = (Func <IDbContextOptionsExtension, DbContextOptions>)contextOptions.WithExtension <IDbContextOptionsExtension>; var withExtension = withExtensionFunc.Method.GetGenericMethodDefinition().MakeGenericMethod(new[] { extension.GetType() }); contextOptions = (DbContextOptions)withExtension.Invoke(contextOptions, new[] { extension }); } } return(Fix.FixHelper.FixDistinctCount(contextOptions)); }
public MusicZoneDbContext(DbContextOptions <MusicZoneDbContext> options) : base(options) { var extension = options.FindExtension <SqlServerOptionsExtension>(); this.connectionString = extension.ConnectionString; }
public DataContext(DbContextOptions <DataContext> options) : base(options) { if (options.FindExtension <Microsoft.EntityFrameworkCore.Sqlite.Infrastructure.Internal.SqliteOptionsExtension>() != null) { _isSqlLte = true; } }
public IdentityServerDbContext(DbContextOptions <IdentityServerDbContext> options) : base(options) { var extension = options.FindExtension <SqlServerOptionsExtension>(); _connectionString = extension.ConnectionString; //_connectionString = Configure.ConfigurationBuilder().Build().GetConnectionString("IdentityConnectionDb"); }
static void Configure_Mapping(ModelBuilder modelBuilder, DbContextOptions dbContextOptions, DbContext dbContext) { if (!CanConfigure(dbContextOptions)) { return; } var coreOption = dbContextOptions.FindExtension <CoreOptionAquirrelExtension>(); var EntityMapping__type = typeof(EntityMapping <>); var IEntityMapping_typeInfo = typeof(IEntityMapping).GetTypeInfo(); var IEntityBase__type = typeof(IEntityBase <>); var EntityBase_type = typeof(EntityBase); Type[] allMappingEntityTypes = Array.Empty <Type>(); //装载显示mapping的entites if (coreOption.EntityMappingsAssebmlys != null && coreOption.EntityMappingsAssebmlys.Any()) { Console.WriteLine("auto mapping impl IEntityMapping,EntityMapping<,> entity。assebmlys:" + coreOption.EntityMappingsAssebmlys.Select(ass => ass.FullName).ConcatEx(",")); //所有ass的types var allAssebmlysTypes = coreOption.EntityMappingsAssebmlys.SelectMany(ass => ass.GetTypes()).ToArray(); //所有显示mapping的mappings var allMappings = allAssebmlysTypes .Where(type => type.GetTypeInfo().IsClass) //当前类型是class .Where(type => !type.IsGenericType) .Where(type => IEntityMapping_typeInfo.IsAssignableFrom(type)) //当前类型是IEntityMapping接口的实现 .ToArray(); //所有显示mapping的实体 allMappingEntityTypes = allMappings.Select(type => type.GetTypeInfo().BaseType.GetTypeInfo().GetGenericArguments()[0]).ToArray(); //装载显示实现了mapping的实体 allMappings.Each(type => (Activator.CreateInstance(type) as IEntityMapping).Mapping(modelBuilder)); } //自动装载实现了IEntityBase的entites if (coreOption.EntityAssebmlys != null && coreOption.EntityAssebmlys.Any()) { Console.WriteLine("auto add entity type with impl IEntityBase。assebmlys:" + coreOption.EntityAssebmlys.Select(ass => ass.FullName).ConcatEx(",")); var allEntityTypes = coreOption.EntityAssebmlys .SelectMany(ass => ass.GetTypes()) //所有要自动发现entity的assebmly .Select(type => new { type = type, typeInfo = type.GetTypeInfo() }) //投影 .Where(type => type.typeInfo.IsClass) //当前类型是class .Where(type => !type.typeInfo.IsAbstract) //当前类型不是抽象类 .Where(type => type.type != EntityBase_type) //不是entity基类本身 //当前类型所实现的接口中存在IEntityBase<> .Where(type => type.typeInfo.GetInterfaces().Any(i => i.GetTypeInfo().IsGenericType&& i.GetGenericTypeDefinition() == IEntityBase__type)) .Select(type => type.type) .ToArray(); allEntityTypes .Except(allMappingEntityTypes) .Each(type => { //var entityKeyType = type.GetTypeInfo().GetInterfaces().Single(extendInterface => extendInterface.GetTypeInfo().IsGenericType && extendInterface.GetGenericTypeDefinition() == IEntityBase__type).GetTypeInfo().GenericTypeArguments[0]; (Activator.CreateInstance(typeof(EntityMapping <>).MakeGenericType(type)) as IEntityMapping).Mapping(modelBuilder); }); } }
public DoormanContext(DbContextOptions <DoormanContext> options) : base(options) { if (options.FindExtension <InMemoryOptionsExtension>() == null) { Database.Migrate(); } }
public TestContext(DbContextOptions <TestContext> options) : base(options) { _connectionString = options.FindExtension <SqlServerOptionsExtension>().ConnectionString; //extension.ConnectionString = connectionString; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { string connString = _context.FindExtension <Microsoft.EntityFrameworkCore.Infrastructure.Internal.SqlServerOptionsExtension>().ConnectionString; optionsBuilder.UseSqlServer(connString); } }
public CoreDbContext(DbContextOptions options) : base(options) { var serviceProvider = options.FindExtension <CoreOptionsExtension>().ApplicationServiceProvider; var eventBus = serviceProvider.GetService <IEventBus>(); EntityChangeEvent = new EntityChangeEventPublish(eventBus); }
protected internal static DbContextOptions <T> MutateOptionsType <T>(DbContextOptions options) where T : DbContext { var jetDbContextOptions = options.FindExtension <JetOptionsExtension>(); return(new DbContextOptionsBuilder <T>() .UseJet(jetDbContextOptions.ConnectionString) .Options); }
protected SqlServerContextBase(DbContextOptions options) : base(options) { var schemaExt = options.FindExtension <DbContextOptionsSchemaExtension>(); if (schemaExt != null) { DbSchema = schemaExt.DbSchema; } }
public UniversityDataContext(DbContextOptions <UniversityDataContext> options) { var sqlServerOptionsExtension = options.FindExtension <SqlServerOptionsExtension>(); if (sqlServerOptionsExtension != null) { _connStr = sqlServerOptionsExtension.ConnectionString; } }
protected override PersistentConfigurationDbContext CreateNewInstance(DbContextOptions <PersistentConfigurationDbContext> options) { var optionsBuilder = new DbContextOptionsBuilder <PersistedGrantDbContext>(); var extension = options.FindExtension <SqliteOptionsExtension>(); optionsBuilder.UseSqlite(extension.ConnectionString); return(new PersistentConfigurationDbContext(optionsBuilder.Options, new OperationalStoreOptions())); }
public MoviesCupApiContext(DbContextOptions <MoviesCupApiContext> options, string moviesUrlSource = "") : base(options) { UrlMoviesSource = (!String.IsNullOrEmpty(moviesUrlSource)) ? moviesUrlSource : UrlMoviesSource; if (options.FindExtension <InMemoryOptionsExtension>() != null) { MovieModel model = new MovieModel(this); model.Init(UrlMoviesSource); } }
public ApplicationDbContext( DbContextOptions <ApplicationDbContext> options ) : base(options) { var schemaNameOptions = options.FindExtension <SchemaNameOptionsExtension>(); _schemaName = schemaNameOptions is null ? "database" : schemaNameOptions.SchemaName; }
public SqlDatabase(DbContextOptions <SqlDatabase> options) : base(options) { _scnConexao = new SqlConnection { ConnectionString = options.FindExtension <SqlServerOptionsExtension>().ConnectionString }; Conectar(); }
public static DbConnection GetConnection(this DbContextOptions options) { if (options.Extensions.FirstOrDefault(t => t is MySqlOptionsExtension) is MySqlOptionsExtension ext) { return(new MySqlConnection(ext.ConnectionString)); } return(new SqlConnection(options.FindExtension <SqlServerOptionsExtension>().ConnectionString)); }
protected override void OnModelCreating(ModelBuilder modelBuilder) { var entityTypeDefinitionExtension = _options.FindExtension <EntityTypeDefinitionsExtension>(); foreach (var entityTypeDefinition in entityTypeDefinitionExtension.EntityTypeDefinitions) { entityTypeDefinition.Configure(modelBuilder); } }
public ExampleContext(DbContextOptions <ExampleContext> options) : base(options) { if (connectionString == null) { var extension = options.FindExtension <SqlServerOptionsExtension>(); connectionString = extension.ConnectionString; } }
/// <summary> /// /// </summary> /// <param name="options"></param> /// <returns></returns> protected override AppConfigurationDbContext CreateNewInstance(DbContextOptions <AppConfigurationDbContext> options) { var optionsBuilder = new DbContextOptionsBuilder <ConfigurationDbContext>(); var extension = options.FindExtension <SqliteOptionsExtension>(); optionsBuilder.UseSqlite(extension.ConnectionString); return(new AppConfigurationDbContext(optionsBuilder.Options, new ConfigurationStoreOptions())); }
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { SqlServerOptionsExtension extension = options.FindExtension<SqlServerOptionsExtension>(); if (extension != null) this.ConnectionString = extension.ConnectionString; else this.ConnectionString = this.Database.GetDbConnection().ConnectionString; }
public AIMSDbContext(DbContextOptions options) : base(options) { var sqlServerOptionsExtension = options.FindExtension <SqlServerOptionsExtension>(); if (sqlServerOptionsExtension != null) { ConnectionString = sqlServerOptionsExtension.ConnectionString; } }