Esempio n. 1
0
        public static async Task <ReverseEngineerResult> LaunchExternalRunnerAsync(ReverseEngineerOptions options, CodeGenerationMode codeGenerationMode)
        {
            var commandOptions = new ReverseEngineerCommandOptions
            {
                ConnectionString                   = options.ConnectionString,
                ContextClassName                   = options.ContextClassName,
                CustomReplacers                    = options.CustomReplacers,
                Dacpac                             = options.Dacpac,
                DatabaseType                       = options.DatabaseType,
                DefaultDacpacSchema                = options.DefaultDacpacSchema,
                IncludeConnectionString            = options.IncludeConnectionString,
                OutputPath                         = options.OutputPath,
                ContextNamespace                   = options.ContextNamespace,
                ModelNamespace                     = options.ModelNamespace,
                OutputContextPath                  = options.OutputContextPath,
                UseSchemaFolders                   = options.UseSchemaFolders,
                ProjectPath                        = options.ProjectPath,
                ProjectRootNamespace               = options.ProjectRootNamespace,
                SelectedHandlebarsLanguage         = options.SelectedHandlebarsLanguage,
                SelectedToBeGenerated              = options.SelectedToBeGenerated,
                Tables                             = options.Tables,
                UseDatabaseNames                   = options.UseDatabaseNames,
                UseFluentApiOnly                   = options.UseFluentApiOnly,
                UseHandleBars                      = options.UseHandleBars,
                UseInflector                       = options.UseInflector,
                UseLegacyPluralizer                = options.UseLegacyPluralizer,
                UseSpatial                         = options.UseSpatial,
                UseDbContextSplitting              = options.UseDbContextSplitting,
                UseNodaTime                        = options.UseNodaTime,
                UseBoolPropertiesWithoutDefaultSql = options.UseBoolPropertiesWithoutDefaultSql,
                UseNullableReferences              = options.UseNullableReferences,
                UseNoConstructor                   = options.UseNoConstructor,
                UseNoNavigations                   = options.UseNoNavigations,
                UseNoObjectFilter                  = options.UseNoObjectFilter,
            };

            var launcher = new EfRevEngLauncher(commandOptions, codeGenerationMode);

            return(await launcher.GetOutputAsync());
        }
Esempio n. 2
0
        public static string GenerateCode(Compilation compilation, string template, CodeGenerationMode mode)
        {
            CodeGeneratorCore generatorCore = new(compilation, template, mode);

            return(generatorCore.GenerateCode());
        }
        public static async Task <ReverseEngineerResult> LaunchExternalRunnerAsync(ReverseEngineerOptions options, CodeGenerationMode codeGenerationMode)
        {
            var databaseObjects = options.Tables;

            if (databaseObjects.Where(t => t.ObjectType == ObjectType.Table).Count() == 0)
            {
                // No tables selected, so add a dummy table in order to generate an empty DbContext
                databaseObjects.Add(new SerializationTableModel($"Dummy_{new Guid(GuidList.guidDbContextPackagePkgString)}", ObjectType.Table, null));
            }

            var commandOptions = new ReverseEngineerCommandOptions
            {
                ConnectionString                   = options.ConnectionString,
                ContextClassName                   = options.ContextClassName,
                CustomReplacers                    = options.CustomReplacers,
                Dacpac                             = options.Dacpac,
                DatabaseType                       = options.DatabaseType,
                DefaultDacpacSchema                = options.DefaultDacpacSchema,
                IncludeConnectionString            = options.IncludeConnectionString,
                OutputPath                         = options.OutputPath,
                ContextNamespace                   = options.ContextNamespace,
                ModelNamespace                     = options.ModelNamespace,
                OutputContextPath                  = options.OutputContextPath,
                UseSchemaFolders                   = options.UseSchemaFolders,
                ProjectPath                        = options.ProjectPath,
                ProjectRootNamespace               = options.ProjectRootNamespace,
                SelectedHandlebarsLanguage         = options.SelectedHandlebarsLanguage,
                SelectedToBeGenerated              = options.SelectedToBeGenerated,
                Tables                             = databaseObjects,
                UseDatabaseNames                   = options.UseDatabaseNames,
                UseFluentApiOnly                   = options.UseFluentApiOnly,
                UseHandleBars                      = options.UseHandleBars,
                UseInflector                       = options.UseInflector,
                UseLegacyPluralizer                = options.UseLegacyPluralizer,
                UseSpatial                         = options.UseSpatial,
                UseDbContextSplitting              = options.UseDbContextSplitting,
                UseNodaTime                        = options.UseNodaTime,
                UseBoolPropertiesWithoutDefaultSql = options.UseBoolPropertiesWithoutDefaultSql,
                UseNullableReferences              = options.UseNullableReferences,
                UseNoConstructor                   = options.UseNoConstructor,
                UseNoNavigations                   = options.UseNoNavigations,
                UseNoObjectFilter                  = options.UseNoObjectFilter,
                UseNoDefaultConstructor            = options.UseNoDefaultConstructor,
            };

            var launcher = new EfRevEngLauncher(commandOptions, codeGenerationMode);

            return(await launcher.GetOutputAsync());
        }
Esempio n. 4
0
        private async Task <List <TableModel> > GetTablesAsync(DatabaseConnectionModel dbInfo, CodeGenerationMode codeGenerationMode, SchemaInfo[] schemas)
        {
            if (dbInfo.DataConnection != null)
            {
                dbInfo.DataConnection.Open();
                dbInfo.ConnectionString = DataProtection.DecryptString(dbInfo.DataConnection.EncryptedConnectionString);
            }

            var builder = new TableListBuilder(dbInfo.ConnectionString, dbInfo.DatabaseType, schemas);

            return(await builder.GetTableDefinitionsAsync(codeGenerationMode));
        }
Esempio n. 5
0
        private async Task <List <TableModel> > GetDacpacTablesAsync(string dacpacPath, CodeGenerationMode codeGenerationMode)
        {
            var builder = new TableListBuilder(dacpacPath, DatabaseType.SQLServerDacpac, null);

            return(await builder.GetTableDefinitionsAsync(codeGenerationMode));
        }
        private async Task <List <TableModel> > GetDacpacTablesAsync(string dacpacPath, CodeGenerationMode codeGenerationMode)
        {
            TableListBuilder builder;

            if (dacpacPath.EndsWith(".edmx", StringComparison.OrdinalIgnoreCase))
            {
                builder = new TableListBuilder(dacpacPath, DatabaseType.Edmx, null);
            }
            else
            {
                builder = new TableListBuilder(dacpacPath, DatabaseType.SQLServerDacpac, null);
            }

            return(await builder.GetTableDefinitionsAsync(codeGenerationMode));
        }