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

            _internalConfiguration.CheckNotLocked("SetHistoryContextFactory");
            _internalConfiguration.RegisterSingleton(historyContextFactory, typeof(TMigrationsConfiguration));
        }
示例#2
0
            public void Delegates_to_internal_configuration()
            {
                var mockInternalConfiguration = new Mock <InternalConfiguration>(null, null, null, null);
                HistoryContextFactory factory = (e, d) => null;

                new DbConfiguration(mockInternalConfiguration.Object)
                .SetHistoryContextFactory <DbMigrationsConfiguration>(factory);

                mockInternalConfiguration.Verify(m => m.RegisterSingleton(factory, typeof(DbMigrationsConfiguration)));
            }
示例#3
0
        public void Setting_HistoryContextFactory_to_null_results_in_default_factory_being_used()
        {
            var config = new TestMigrationsConfiguration();

            HistoryContextFactory factory = (e, c) => { throw new NotImplementedException(); };

            config.HistoryContextFactory = factory;
            Assert.Same(factory, config.HistoryContextFactory);

            config.HistoryContextFactory = null;
            Assert.IsType <HistoryContextFactory>(config.HistoryContextFactory);
            Assert.NotSame(factory, config.HistoryContextFactory);
        }
示例#4
0
 public DbMigrator CreateMigrator <TContext>(
     bool automaticMigrationsEnabled = true,
     bool automaticDataLossEnabled   = false,
     string targetDatabase           = null,
     string contextKey = null,
     HistoryContextFactory historyContextFactory = null,
     params ScaffoldedMigration[] scaffoldedMigrations)
     where TContext : DbContext
 {
     return(new DbMigrator(
                CreateMigrationsConfiguration <TContext>(
                    automaticMigrationsEnabled,
                    automaticDataLossEnabled,
                    targetDatabase,
                    contextKey,
                    historyContextFactory,
                    scaffoldedMigrations)));
 }
示例#5
0
        public DbMigrationsConfiguration CreateMigrationsConfiguration <TContext>(
            bool automaticMigrationsEnabled = true,
            bool automaticDataLossEnabled   = false,
            string targetDatabase           = null,
            string contextKey = null,
            HistoryContextFactory 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);
        }
示例#6
0
        public HistoryRepository(
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            int?commandTimeout,
            IEnumerable <string> schemas = null,
            HistoryContextFactory historyContextFactory = null)
            : base(connectionString, providerFactory)
        {
            DebugCheck.NotEmpty(contextKey);

            _contextKey     = contextKey;
            _commandTimeout = commandTimeout;

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

            _historyContextFactory
                = historyContextFactory
                  ?? DbConfiguration.GetService <HistoryContextFactory>();
        }
        public HistoryRepository(
            string connectionString,
            DbProviderFactory providerFactory,
            string contextKey,
            int? commandTimeout,
            IEnumerable<string> schemas = null,
            HistoryContextFactory historyContextFactory = null)
            : base(connectionString, providerFactory)
        {
            DebugCheck.NotEmpty(contextKey);

            _contextKey = contextKey;
            _commandTimeout = commandTimeout;

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

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