コード例 #1
0
        public virtual IEnumerable<Migration> GetMigrations([CanBeNull] string contextTypeName)
        {
            var contextType = GetContextType(contextTypeName);
            using (var context = CreateContext(contextType))
            {
                var services = new DesignTimeServices(((IAccessor<IServiceProvider>)context).Service);
                var migrationAssembly = services.GetRequiredService<MigrationAssembly>();

                return migrationAssembly.Migrations;
            }
        }
コード例 #2
0
        public virtual IEnumerable <Migration> GetMigrations([CanBeNull] string contextTypeName)
        {
            var contextType = GetContextType(contextTypeName);

            using (var context = CreateContext(contextType))
            {
                var services          = new DesignTimeServices(((IAccessor <IServiceProvider>)context).Service);
                var migrationAssembly = services.GetRequiredService <MigrationAssembly>();

                return(migrationAssembly.Migrations);
            }
        }
コード例 #3
0
        public virtual MigrationFiles RemoveMigration(
            [CanBeNull] string contextTypeName,
            [NotNull] string rootNamespace,
            [NotNull] string projectDir)
        {
            Check.NotEmpty(rootNamespace, nameof(rootNamespace));
            Check.NotEmpty(projectDir, nameof(projectDir));

            var contextType = GetContextType(contextTypeName);

            using (var context = CreateContext(contextType))
            {
                var services   = new DesignTimeServices(((IAccessor <IServiceProvider>)context).Service);
                var scaffolder = CreateScaffolder(services);

                return(scaffolder.RemoveMigration(projectDir, rootNamespace));
            }
        }
コード例 #4
0
        public virtual MigrationFiles AddMigration(
            [NotNull] string migrationName,
            [CanBeNull] string contextTypeName,
            [NotNull] string rootNamespace,
            [NotNull] string projectDir)
        {
            Check.NotEmpty(migrationName, nameof(migrationName));
            Check.NotEmpty(rootNamespace, nameof(rootNamespace));
            Check.NotEmpty(projectDir, nameof(projectDir));

            var contextType = GetContextType(contextTypeName);
            using (var context = CreateContext(contextType))
            {
                var services = new DesignTimeServices(((IAccessor<IServiceProvider>)context).Service);

                var scaffolder = CreateScaffolder(services);
                var migration = scaffolder.ScaffoldMigration(migrationName, rootNamespace);
                var files = scaffolder.Write(projectDir, migration);

                return files;
            }
        }
コード例 #5
0
        public virtual MigrationFiles AddMigration(
            [NotNull] string migrationName,
            [CanBeNull] string contextTypeName,
            [CanBeNull] string startupAssemblyName,
            [NotNull] string rootNamespace,
            [NotNull] string projectDir)
        {
            Check.NotEmpty(migrationName, nameof(migrationName));
            Check.NotEmpty(rootNamespace, nameof(rootNamespace));
            Check.NotEmpty(projectDir, nameof(projectDir));

            var contextType = GetContextType(contextTypeName);

            using (var context = CreateContext(contextType, startupAssemblyName))
            {
                var services = new DesignTimeServices(((IAccessor <IServiceProvider>)context).Service);

                var scaffolder = CreateScaffolder(services);
                var migration  = scaffolder.ScaffoldMigration(migrationName, rootNamespace);
                var files      = scaffolder.Write(projectDir, migration);

                return(files);
            }
        }
コード例 #6
0
        public virtual MigrationFiles RemoveMigration(
            [CanBeNull] string contextTypeName,
            [CanBeNull] string startupAssemblyName,
            [NotNull] string rootNamespace,
            [NotNull] string projectDir)
        {
            Check.NotEmpty(rootNamespace, nameof(rootNamespace));
            Check.NotEmpty(projectDir, nameof(projectDir));

            var contextType = GetContextType(contextTypeName);
            using (var context = CreateContext(contextType, startupAssemblyName))
            {
                var services = new DesignTimeServices(((IAccessor<IServiceProvider>)context).Service);
                var scaffolder = CreateScaffolder(services);

                var files = scaffolder.RemoveMigration(projectDir, rootNamespace);

                _logger.Value.LogInformation(Strings.Done);

                return files;
            }
        }