コード例 #1
0
        public static IEnumerable <ExtendProperty> GetMsDescriptionForDbObject(this DbConnection connection, IDbObject dbObject)
        {
            var repository = new ExtendPropertyRepository();

            var name       = "'MS_Description'";
            var level0type = "'schema'";
            var level0name = string.Format("'{0}'", dbObject.Schema);
            var level1type = string.Format("'{0}'", dbObject.Type);
            var level1name = string.Format("'{0}'", dbObject.Name);
            var level2type = "default";
            var level2name = "default";

            return(repository.GetExtendProperties(connection, name, level0type, level0name, level1type, level1name, level2type, level2name).ToList());
        }
コード例 #2
0
        public static void DropMsDescription(this SqlServerDatabaseFactory databaseFactory, ITable table, Column column)
        {
            var repository = new ExtendPropertyRepository();

            var name       = "MS_Description";
            var level0type = "schema";
            var level0name = table.Schema;
            var level1type = "table";
            var level1name = table.Name;
            var level2type = "column";
            var level2name = column.Name;

            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                repository.DropExtendedProperty(connection, name, level0type, level0name, level1type, level1name, level2type, level2name);
            }
        }
コード例 #3
0
        public static void UpdateMsDescription(this SqlServerDatabaseFactory databaseFactory, ITable table, string description)
        {
            var repository = new ExtendPropertyRepository();

            var name       = "MS_Description";
            var level0type = "schema";
            var level0name = table.Schema;
            var level1type = "table";
            var level1name = table.Name;
            var level2type = string.Empty;
            var level2name = string.Empty;

            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                repository.UpdateExtendedProperty(connection, name, description, level0type, level0name, level1type, level1name, level2type, level2name);

                table.Description = description;
            }
        }
コード例 #4
0
        public virtual Database Import()
        {
            var database = new Database();

            database.Mappings = DatabaseTypeMapList.Definition;

            var extendPropertyRepository = new ExtendPropertyRepository();

            using (var connection = GetConnection())
            {
                connection.Open();

                database.Name = connection.Database;

                var dbObjects = GetDbObjects(connection).ToList();

                foreach (var dbObject in dbObjects)
                {
                    if (ImportSettings.Exclusions.Contains(dbObject.FullName))
                    {
                        continue;
                    }

                    database.DbObjects.Add(dbObject);
                }

                if (ImportSettings.ImportTables)
                {
                    Logger?.LogInformation("Importing tables for '{0}'...", database.Name);

                    foreach (var table in GetTables(connection, database.GetTables()))
                    {
                        if (ImportSettings.Exclusions.Contains(table.FullName))
                        {
                            continue;
                        }

                        ImportDescription(connection, table);

                        database.Tables.Add(table);
                    }
                }

                if (ImportSettings.ImportViews)
                {
                    Logger?.LogInformation("Importing views for '{0}'...", database.Name);

                    foreach (var view in GetViews(connection, database.GetViews()))
                    {
                        if (ImportSettings.Exclusions.Contains(view.FullName))
                        {
                            continue;
                        }

                        ImportDescription(connection, view);

                        database.Views.Add(view);
                    }
                }

                if (ImportSettings.ImportStoredProcedures)
                {
                    Logger?.LogInformation("Importing stored procedures for '{0}'...", database.Name);

                    foreach (var storedProcedure in GetStoredProcedures(connection, database.GetStoredProcedures()))
                    {
                        if (ImportSettings.Exclusions.Contains(storedProcedure.FullName))
                        {
                            continue;
                        }

                        ImportDescription(connection, storedProcedure);

                        database.StoredProcedures.Add(storedProcedure);
                    }
                }

                if (ImportSettings.ImportTableFunctions)
                {
                    Logger?.LogInformation("Importing table functions for '{0}'...", database.Name);

                    foreach (var tableFunction in GetTableFunctions(connection, database.GetTableFunctions()))
                    {
                        if (ImportSettings.Exclusions.Contains(tableFunction.FullName))
                        {
                            continue;
                        }

                        ImportDescription(connection, tableFunction);

                        database.TableFunctions.Add(tableFunction);
                    }
                }

                if (ImportSettings.ImportScalarFunctions)
                {
                    Logger?.LogInformation("Importing scalar functions for '{0}'...", database.Name);

                    foreach (var scalarFunction in GetScalarFunctions(connection, database.GetScalarFunctions()))
                    {
                        if (ImportSettings.Exclusions.Contains(scalarFunction.FullName))
                        {
                            continue;
                        }

                        ImportDescription(connection, scalarFunction);

                        database.ScalarFunctions.Add(scalarFunction);
                    }
                }
            }

            return(database);
        }