internal static BaseDbContext GetDbContext(string conString, DatabaseType dbType, List <Type> entityTypes = null) { AbstractProvider provider = GetProvider(dbType); DbConnection dbConnection = provider.GetDbConnection(); dbConnection.ConnectionString = conString; IModel model; if (entityTypes?.Count > 0) { model = DbModelFactory.BuildDbCompiledModel(dbType, entityTypes); } else { model = DbModelFactory.GetDbCompiledModel(conString, dbType); } DbContextOptionsBuilder builder = new DbContextOptionsBuilder(); provider.UseDatabase(builder, dbConnection); builder.EnableSensitiveDataLogging(); builder.UseModel(model); builder.UseLoggerFactory(_loggerFactory); return(new BaseDbContext(builder.Options)); }
public IConfigInit AddPhysicTable <TEntity>(string physicTableName, string groupName = "BaseDbGroup") { var absEntityType = typeof(TEntity); _lock.EnterReadLock(); bool exists = _physicTables.Any(x => x.AbsTableName == absEntityType.Name && x.GroupName == groupName && x.PhysicTableName == physicTableName); _lock.ExitReadLock(); if (exists) { return(this); } _lock.EnterWriteLock(); _physicTables.Add(new PhysicTable { AbsTableName = absEntityType.Name, GroupName = groupName, PhysicTableName = physicTableName }); _lock.ExitWriteLock(); var physicEntityType = ShardingHelper.MapTable(absEntityType, physicTableName); DbModelFactory.AddEntityType(physicTableName, physicEntityType); return(this); }
private Type MapTable(string targetTableName) { return(DbModelFactory.GetEntityType(targetTableName)); }