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

            _internalConfiguration.CheckNotLocked("SetHistoryContextFactory");
            _internalConfiguration.RegisterSingleton(historyContextFactory, typeof(TMigrationsConfiguration));
        }
예제 #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)));
 }
예제 #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);
        }
예제 #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>();
        }
예제 #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>();
        }