/// <summary> /// This returns a DesignTimeProvider for the design time service instance that you provided /// </summary> /// <param name="designTimeService">This should be an instance of rhe design time service for the database provider</param> /// <returns></returns> public static ServiceProvider GetDesignTimeProvider(this IDesignTimeServices designTimeService) { // Add base services for scaffolding var serviceCollection = new ServiceCollection() .AddEntityFrameworkDesignTimeServices() .AddSingleton <IOperationReporter, OperationReporter>() .AddSingleton <IOperationReportHandler, OperationReportHandler>(); designTimeService.ConfigureDesignTimeServices(serviceCollection); return(serviceCollection.BuildServiceProvider()); }
static internal IDesignTimeServices GetDesignTimeServices(DatabaseProviders?provider, string dtsClassName = null) { if (string.IsNullOrEmpty(dtsClassName)) { if (provider == null || !DatabaseProviderDtsClasses.TryGetValue(provider.Value, out dtsClassName)) { throw new NotSupportedException($"The specified provider [{provider}] DTS class could not be resolved, and no custom class was specified"); } } var dtsClass = Type.GetType(dtsClassName); if (dtsClass == null) { // foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) // { // Console.Error.WriteLine(" * Looking in ASM: " + a.FullName); // dtsClass = a.GetType(dtsClassName); // if (dtsClass != null) // { // break; // } // } if (dtsClass == null) { throw new NotSupportedException($"Could not resolve DTS for provider class [{dtsClassName}]"); } } IDesignTimeServices dts = (IDesignTimeServices)Activator.CreateInstance(dtsClass); if (dts == null) { throw new NotSupportedException($"Could not resolve DTS class for provider class [{dtsClassName}]"); } return(dts); }
private DatabaseModel GetDatabaseModelViaScaffolder(DbContext context, string configOrConnectionString, IDesignTimeServices designTimeService) { var serviceProvider = designTimeService.GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); var connectionString = configOrConnectionString == null ? context.Database.GetDbConnection().ConnectionString : GetConfigurationOrActualString(configOrConnectionString); var databaseModel = factory.Create(connectionString, new string[] { }, new string[] { }); RemoveAnyTabletoIgnore(databaseModel); return(databaseModel); }
//------------------------------------------------------ //private methods private bool FinishRestOfCompare(string configOrConnectionString, DbContext[] dbContexts, IDesignTimeServices designTimeService) { var databaseModel = GetDatabaseModelViaScaffolder(dbContexts[0], configOrConnectionString, designTimeService); bool hasErrors = false; foreach (var context in dbContexts) { var stage1Comparer = new Stage1Comparer(context.Model, context.GetType().Name, _logs, _config.LogsToIgnore); hasErrors |= stage1Comparer.CompareModelToDatabase(databaseModel); } if (hasErrors) { return(true); } //No errors, so its worth running the second phase var stage2Comparer = new Stage2Comparer(databaseModel, _config.LogsToIgnore); hasErrors = stage2Comparer.CompareLogsToDatabase(_logs); _logs.AddRange(stage2Comparer.Logs); return(hasErrors); }
private DatabaseModel GetDatabaseModelViaScaffolder(DbContext[] contexts, string connectionString, IDesignTimeServices designTimeService) { var serviceProvider = designTimeService.GetDesignTimeProvider(); var factory = (IDatabaseModelFactory)serviceProvider.GetService(typeof(IDatabaseModelFactory)); var databaseModel = factory.Create(connectionString, new DatabaseModelFactoryOptions(new string[] { }, new string[] { })); RemoveAnyTableToIgnore(databaseModel, contexts); return(databaseModel); }
private DatabaseModel GetDatabaseModelViaScaffolder(DbContext[] contexts, string connectionString, IDesignTimeServices designTimeService) { var serviceProvider = designTimeService.GetDesignTimeProvider(); var factory = serviceProvider.GetService <IDatabaseModelFactory>(); #if NETSTANDARD2_0 var databaseModel = factory.Create(connectionString, new string[] { }, new string[] { }); #elif NETSTANDARD2_1 var databaseModel = factory.Create(connectionString, new DatabaseModelFactoryOptions(new string[] { }, new string[] { })); #endif RemoveAnyTableToIgnore(databaseModel, contexts); return(databaseModel); }