public virtual void BuildDBContext(DbContextOptionsBuilder options) { var migrationsAssembly = MigrationAssembly.GetName().Name; var connectionString = GetConnectionString(); var dbServerEngine = GetDatabaseServerEngine(); switch (dbServerEngine) { case SupportedDatabaseServerEngines.MSSQL: options.UseSqlServer(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); break; case SupportedDatabaseServerEngines.PostgreSQL: options.UseNpgsql(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); break; case SupportedDatabaseServerEngines.MySQL: options.UseMySQL(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); break; case SupportedDatabaseServerEngines.SQLite: options.UseSqlite(connectionString, sql => sql.MigrationsAssembly(migrationsAssembly)); break; case SupportedDatabaseServerEngines.None: default: break; } }
/// <summary> /// Initialize MigrationCallingName and MigrationAssembly from <paramref name="model"/> /// </summary> /// <param name="model"></param> protected void InitMetadata(IMigrationModel model) { if (model == null) { return; } MigrationAssembly = model.GetType().Assembly; if (MigrationCallingNameConfigField.IsEmpty()) { MigrationName = MigrationAssembly.GetName().Name; } }
/// <summary> /// Default Constructor /// </summary> /// <param name="migrationSourceItem"></param> public MigrationMetadata(IMigrationSourceItem migrationSourceItem = null) { if (migrationSourceItem != null) { MigrationAssembly = migrationSourceItem.MigrationTypeCandidates?.FirstOrDefault()?.Assembly; if (MigrationAssembly != null) { MigrationName = MigrationAssembly.GetName().Name; return; } } MigrationAssembly = Assembly.GetCallingAssembly(); MigrationName = MigrationAssembly.GetName().Name; }
/// <inheritdoc /> public override string ToString() { return($"{{ {nameof(MigrationMetadata)} [{nameof(MigrationAssembly)}.Name:{MigrationAssembly.GetName().Name}, {nameof(MigrationName)}:{MigrationName}] }}"); }