Beispiel #1
0
        protected internal void SetHistoryContextFactory <TMigrationsConfiguration>(IHistoryContextFactory historyContextFactory)
            where TMigrationsConfiguration : DbMigrationsConfiguration
        {
            Check.NotNull(historyContextFactory, "historyContextFactory");

            _internalConfiguration.CheckNotLocked("SetHistoryContextFactory");
            _internalConfiguration.RegisterSingleton(historyContextFactory, typeof(TMigrationsConfiguration));
        }
Beispiel #2
0
 public DbMigrator CreateMigrator <TContext>(
     bool automaticMigrationsEnabled = true,
     bool automaticDataLossEnabled   = false,
     string targetDatabase           = null,
     string contextKey = null,
     IHistoryContextFactory historyContextFactory = null,
     params ScaffoldedMigration[] scaffoldedMigrations)
     where TContext : DbContext
 {
     return(new DbMigrator(
                CreateMigrationsConfiguration <TContext>(
                    automaticMigrationsEnabled,
                    automaticDataLossEnabled,
                    targetDatabase,
                    contextKey,
                    historyContextFactory,
                    scaffoldedMigrations)));
 }
Beispiel #3
0
        public DbMigrationsConfiguration CreateMigrationsConfiguration <TContext>(
            bool automaticMigrationsEnabled = true,
            bool automaticDataLossEnabled   = false,
            string targetDatabase           = null,
            string contextKey = null,
            IHistoryContextFactory historyContextFactory = null,
            params ScaffoldedMigration[] scaffoldedMigrations)
            where TContext : DbContext
        {
            var migrationsConfiguration
                = new DbMigrationsConfiguration
                {
                AutomaticMigrationsEnabled        = automaticMigrationsEnabled,
                AutomaticMigrationDataLossAllowed = automaticDataLossEnabled,
                ContextType           = typeof(TContext),
                MigrationsAssembly    = SystemComponentModelDataAnnotationsAssembly,
                MigrationsNamespace   = typeof(TContext).Namespace,
                HistoryContextFactory = historyContextFactory
                };

            if (!string.IsNullOrWhiteSpace(contextKey))
            {
                migrationsConfiguration.ContextKey = contextKey;
            }

            if (!string.IsNullOrWhiteSpace(targetDatabase))
            {
                TestDatabase = DatabaseProviderFixture.InitializeTestDatabase(DatabaseProvider, targetDatabase);
            }

            if ((scaffoldedMigrations != null) &&
                scaffoldedMigrations.Any())
            {
                migrationsConfiguration.MigrationsAssembly = MigrationCompiler.Compile(
                    migrationsConfiguration.MigrationsNamespace,
                    scaffoldedMigrations);
            }

            migrationsConfiguration.TargetDatabase = new DbConnectionInfo(TestDatabase.ConnectionString, TestDatabase.ProviderName);

            migrationsConfiguration.CodeGenerator = CodeGenerator;

            return(migrationsConfiguration);
        }
Beispiel #4
0
        public HistoryRepository(
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            IEnumerable <string> schemas = null,
            IHistoryContextFactory historyContextFactory = null)
            : base(connectionString, providerFactory)
        {
            DebugCheck.NotEmpty(contextKey);

            _contextKey = contextKey;

            _schemas
                = new[] { DbDatabaseMetadataExtensions.DefaultSchema }
            .Concat(schemas ?? Enumerable.Empty <string>())
            .Distinct();

            _historyContextFactory
                = historyContextFactory
                  ?? DbConfiguration.GetService <IHistoryContextFactory>();
        }
Beispiel #5
0
        public HistoryRepository(
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            IEnumerable<string> schemas = null,
            IHistoryContextFactory historyContextFactory = null)
            : base(connectionString, providerFactory)
        {
            DebugCheck.NotEmpty(contextKey);

            _contextKey = contextKey;

            _schemas
                = new[] { DbDatabaseMetadataExtensions.DefaultSchema }
                    .Concat(schemas ?? Enumerable.Empty<string>())
                    .Distinct();

            _historyContextFactory
                = historyContextFactory
                  ?? DbConfiguration.GetService<IHistoryContextFactory>();
        }