public virtual Task<ReverseEngineerFiles> ReverseEngineerAsync(
            [NotNull] string provider,
            [NotNull] string connectionString,
            [CanBeNull] string outputDir,
            [CanBeNull] string dbContextClassName,
            [CanBeNull] List<string> schemas,
            [CanBeNull] List<string> tables,
            bool useDataAnnotations,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.NotEmpty(provider, nameof(provider));
            Check.NotEmpty(connectionString, nameof(connectionString));

            var services = _servicesBuilder.Build(provider);

            var loggerFactory = services.GetRequiredService<ILoggerFactory>();
            loggerFactory.AddProvider(_loggerProvider);

            var generator = services.GetRequiredService<ReverseEngineeringGenerator>();
            var tableSelectionSet = new TableSelectionSet(tables, schemas);
            var configuration = new ReverseEngineeringConfiguration
            {
                ConnectionString = connectionString,
                ContextClassName = dbContextClassName,
                ProjectPath = _projectDir,
                ProjectRootNamespace = _rootNamespace,
                OutputPath = outputDir,
                TableSelectionSet = tableSelectionSet,
                UseFluentApiOnly = !useDataAnnotations
            };

            return generator.GenerateAsync(configuration, cancellationToken);
        }
        public override IModel Create(string connectionString, TableSelectionSet tableSelectionSet)
        {
            var model = base.Create(connectionString, tableSelectionSet);

            model.Scaffolding().UseProviderMethodName = nameof(SqlServerDbContextOptionsExtensions.UseSqlServer);
            return(model);
        }
Exemple #3
0
        public virtual DatabaseModel Create(
            [NotNull] string connectionString, [NotNull] TableSelectionSet tableSelectionSet)
        {
            Check.NotEmpty(connectionString, nameof(connectionString));
            Check.NotNull(tableSelectionSet, nameof(tableSelectionSet));

            ResetState();

            using (_connection = new SqliteConnection(connectionString))
            {
                _connection.Open();
                _tableSelectionSet = tableSelectionSet;

                string databaseName = null;
                try
                {
                    databaseName = Path.GetFileNameWithoutExtension(_connection.DataSource);
                }
                catch (ArgumentException)
                {
                    // graceful fallback
                }

                _databaseModel.DatabaseName = !string.IsNullOrEmpty(databaseName) ? databaseName : _connection.DataSource;

                GetSqliteMaster();
                GetColumns();
                GetIndexes();
                GetForeignKeys();
                return(_databaseModel);
            }
        }
        public virtual DatabaseModel Create(string connectionString, TableSelectionSet tableSelectionSet)
        {
            Check.NotEmpty(connectionString, nameof(connectionString));
            Check.NotNull(tableSelectionSet, nameof(tableSelectionSet));

            ResetState();

            using (_connection = new SqlConnection(connectionString))
            {
                _connection.Open();
                _tableSelectionSet = tableSelectionSet;

                _databaseModel.DatabaseName = _connection.Database;
                // TODO actually load per-user
                _databaseModel.DefaultSchemaName = "dbo";

                if (SupportsSequences)
                {
                    GetSequences();
                }

                GetTables();
                GetColumns();
                GetIndexes();
                GetForeignKeys();
                return(_databaseModel);
            }
        }
 private void ResetState()
 {
     _connection        = null;
     _tableSelectionSet = null;
     _databaseModel     = new DatabaseModel();
     _tables            = new Dictionary <string, TableModel>();
     _tableColumns      = new Dictionary <string, ColumnModel>(StringComparer.OrdinalIgnoreCase);
 }
Exemple #6
0
        public virtual IModel Create([NotNull] string connectionString, [CanBeNull] TableSelectionSet tableSelectionSet)
        {
            Check.NotEmpty(connectionString, nameof(connectionString));

            var schemaInfo = _databaseModelFactory.Create(connectionString, tableSelectionSet ?? TableSelectionSet.All);

            return(CreateFromDatabaseModel(schemaInfo));
        }
 private void ResetState()
 {
     _connection = null;
     _tableSelectionSet = null;
     _databaseModel = new DatabaseModel();
     _tables = new Dictionary<string, TableModel>();
     _tableColumns = new Dictionary<string, ColumnModel>(StringComparer.OrdinalIgnoreCase);
 }
Exemple #8
0
 public static bool Allows(this TableSelectionSet tableSet, string tableName)
 {
     if (tableSet == null ||
         tableSet.Tables.Count == 0)
     {
         return(true);
     }
     return(tableSet.Tables.Any(t => t.Equals(tableName, StringComparison.OrdinalIgnoreCase)));
 }
        public static bool Allows(this TableSelectionSet tableSelectionSet, [NotNull] string schemaName, [NotNull] string tableName)
        {
            if ((tableSelectionSet == null) ||
                ((tableSelectionSet.Schemas.Count == 0) &&
                 (tableSelectionSet.Tables.Count == 0)))
            {
                return(true);
            }

            if (tableSelectionSet.Schemas.Contains(schemaName))
            {
                return(true);
            }

            return(tableSelectionSet.Tables.Contains($"{schemaName}.{tableName}", StringComparer.OrdinalIgnoreCase) ||
                   tableSelectionSet.Tables.Contains($"[{schemaName}].[{tableName}]", StringComparer.OrdinalIgnoreCase) ||
                   tableSelectionSet.Tables.Contains($"{schemaName}.[{tableName}]", StringComparer.OrdinalIgnoreCase) ||
                   tableSelectionSet.Tables.Contains($"[{schemaName}].{tableName}", StringComparer.OrdinalIgnoreCase) ||
                   tableSelectionSet.Tables.Contains($"{tableName}", StringComparer.OrdinalIgnoreCase) ||
                   tableSelectionSet.Tables.Contains($"[{tableName}]", StringComparer.OrdinalIgnoreCase));
        }
Exemple #10
0
        public static bool Allows(this TableSelectionSet _tableSelectionSet, [NotNull] string schemaName, [NotNull] string tableName)
        {
            if (_tableSelectionSet == null ||
                (_tableSelectionSet.Schemas.Count == 0 &&
                 _tableSelectionSet.Tables.Count == 0))
            {
                return(true);
            }

            if (_tableSelectionSet.Schemas.Contains(schemaName))
            {
                return(true);
            }

            return(_tableSelectionSet.Tables.Contains($"{schemaName}.{tableName}") ||
                   _tableSelectionSet.Tables.Contains($"[{schemaName}].[{tableName}]") ||
                   _tableSelectionSet.Tables.Contains($"{schemaName}.[{tableName}]") ||
                   _tableSelectionSet.Tables.Contains($"[{schemaName}].{tableName}") ||
                   _tableSelectionSet.Tables.Contains($"{tableName}") ||
                   _tableSelectionSet.Tables.Contains($"[{tableName}]"));
        }
        public virtual DatabaseModel Create(
            [NotNull] string connectionString, [NotNull] TableSelectionSet tableSelectionSet)
        {
            Check.NotEmpty(connectionString, nameof(connectionString));
            Check.NotNull(tableSelectionSet, nameof(tableSelectionSet));

            ResetState();

            using (_connection = new SqliteConnection(connectionString))
            {
                _connection.Open();
                _tableSelectionSet = tableSelectionSet;

                string databaseName = null;
                try
                {
                    databaseName = Path.GetFileNameWithoutExtension(_connection.DataSource);
                }
                catch (ArgumentException)
                {
                    // graceful fallback
                }

                _databaseModel.DatabaseName = !string.IsNullOrEmpty(databaseName) ? databaseName : _connection.DataSource;

                GetSqliteMaster();
                GetColumns();
                GetIndexes();

                foreach (var table in _databaseModel.Tables)
                {
                    SqliteDmlParser.ParseTableDefinition(table, _tableDefinitions[table.Name]);
                }

                GetForeignKeys();
                return _databaseModel;
            }
        }
        public virtual DatabaseModel Create(string connectionString, TableSelectionSet tableSelectionSet)
        {
            Check.NotEmpty(connectionString, nameof(connectionString));
            Check.NotNull(tableSelectionSet, nameof(tableSelectionSet));

            ResetState();

            using (_connection = new SqlConnection(connectionString))
            {
                _connection.Open();
                _tableSelectionSet = tableSelectionSet;

                _databaseModel.DatabaseName = _connection.Database;
                 // TODO actually load per-user
                _databaseModel.DefaultSchemaName = "dbo";

                GetTables();
                GetColumns();
                GetIndexes();
                GetForeignKeys();
                return _databaseModel;
            }
        }
 public override IModel Create(string connectionString, TableSelectionSet tableSelectionSet)
 {
     var model = base.Create(connectionString, tableSelectionSet);
     model.Scaffolding().UseProviderMethodName = nameof(SqliteDbContextOptionsBuilderExtensions.UseSqlite);
     return model;
 }