Exemplo n.º 1
0
        /// <summary>
        /// Adds if not exists or updates if exists an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="view">Instance of <see cref="View"/> class</param>
        /// <param name="column">Instance of <see cref="Column"/> class</param>
        /// <param name="name">Extended property name</param>
        /// <param name="value">Extended property value</param>
        public static void AddOrUpdateExtendedProperty(this SqlServerDatabaseFactory databaseFactory, IView view, Column column, string name, string value)
        {
            var model = new ExtendedProperty(name, "schema", view.Schema, "view", view.Name, "column", column.Name)
            {
                Value = value
            };

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

                var repository = new ExtendedPropertyRepository(connection);

                var extendedProperty = repository.GetExtendedProperties(model).FirstOrDefault();

                if (extendedProperty == null)
                {
                    repository.AddExtendedProperty(model);
                }
                else
                {
                    repository.UpdateExtendedProperty(model);
                }

                column.Description = value;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Drops an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="view">Instance of <see cref="View"/> class</param>
        /// <param name="column">Instance of <see cref="Column"/> class</param>
        /// <param name="name">Extended property name</param>
        public static void DropExtendedProperty(this SqlServerDatabaseFactory databaseFactory, IView view, Column column, string name)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                new ExtendedPropertyRepository(connection).DropExtendedProperty(new ExtendedProperty(name, "schema", view.Schema, "view", view.Name, "column", column.Name));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Drops an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="table">Instance of <see cref="Table"/> class</param>
        /// <param name="name">Extended property name</param>
        public static void DropExtendedProperty(this SqlServerDatabaseFactory databaseFactory, ITable table, string name)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                new ExtendedPropertyRepository(connection).DropExtendedProperty(new ExtendedProperty(name, "schema", table.Schema, "table", table.Name));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Drops an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="database"></param>
        /// <param name="name">Extended property name</param>
        public static void DropExtendedProperty(this SqlServerDatabaseFactory databaseFactory, Database database, string name)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                new ExtendedPropertyRepository(connection).DropExtendedProperty(new ExtendedProperty(name));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Updates an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="database"></param>
        /// <param name="name">Extended property name</param>
        /// <param name="value">Extended property value</param>
        public static void UpdateExtendedProperty(this SqlServerDatabaseFactory databaseFactory, Database database, string name, string value)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                new ExtendedPropertyRepository(connection).UpdateExtendedProperty(new ExtendedProperty(name, value));

                database.Description = value;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="view">Instance of <see cref="View"/> class</param>
        /// <param name="name">Extended property name</param>
        /// <param name="value">Extended property value</param>
        public static void AddExtendedProperty(this SqlServerDatabaseFactory databaseFactory, IView view, string name, string value)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                new ExtendedPropertyRepository(connection).AddExtendedProperty(new ExtendedProperty(name, "schema", view.Schema, "view", view.Name)
                {
                    Value = value
                });

                view.Description = value;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Adds an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="table">Instance of <see cref="Table"/> class</param>
        /// <param name="column">Instance of <see cref="Column"/> class</param>
        /// <param name="name">Extended property name</param>
        /// <param name="value">Extended property value</param>
        public static void AddExtendedProperty(this SqlServerDatabaseFactory databaseFactory, ITable table, Column column, string name, string value)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                new ExtendedPropertyRepository(connection).AddExtendedProperty(new ExtendedProperty(name, "schema", table.Schema, "table", table.Name, "column", column.Name)
                {
                    Value = value
                });

                column.Description = value;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Drops an extended property for database object if exists
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="view">Instance of <see cref="View"/> class</param>
        /// <param name="column">Instance of <see cref="Column"/> class</param>
        /// <param name="name">Extended property name</param>
        public static void DropExtendedPropertyIfExists(this SqlServerDatabaseFactory databaseFactory, IView view, Column column, string name)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                var extendedProperty = connection.GetExtendedProperties(view, name).FirstOrDefault();

                if (extendedProperty != null)
                {
                    new ExtendedPropertyRepository(connection).DropExtendedProperty(new ExtendedProperty(name, "schema", view.Schema, "view", view.Name, "column", column.Name));
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Drops an extended property for database object if exists
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="table">Instance of <see cref="Table"/> class</param>
        /// <param name="name">Extended property name</param>
        public static void DropExtendedPropertyIfExists(this SqlServerDatabaseFactory databaseFactory, ITable table, string name)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                var extendedProperty = connection.GetExtendedProperties(table, name).FirstOrDefault();

                if (extendedProperty != null)
                {
                    new ExtendedPropertyRepository(connection).DropExtendedProperty(new ExtendedProperty(name, "schema", table.Schema, "table", table.Name));
                }
            }
        }
        /// <summary>
        /// Updates an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="view">Instance of <see cref="View"/> class</param>
        /// <param name="column">Instance of <see cref="Column"/> class</param>
        /// <param name="name">Extended property name</param>
        /// <param name="value">Extended property value</param>
        public static void UpdateExtendedProperty(this SqlServerDatabaseFactory databaseFactory, IView view, Column column, string name, string value)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                var repository = new ExtendedPropertyRepository(connection);

                repository.UpdateExtendedProperty(new ExtendedProperty(name, "schema", view.Schema, "view", view.Name, "column", column.Name)
                {
                    Value = value
                });

                column.Description = value;
            }
        }
        /// <summary>
        /// Updates an extended property for database object
        /// </summary>
        /// <param name="databaseFactory">Instance of <see cref="SqlServerDatabaseFactory"/> class</param>
        /// <param name="table">Instance of <see cref="Table"/> class</param>
        /// <param name="name">Extended property name</param>
        /// <param name="value">Extended property value</param>
        public static void UpdateExtendedProperty(this SqlServerDatabaseFactory databaseFactory, ITable table, string name, string value)
        {
            using (var connection = databaseFactory.GetConnection())
            {
                connection.Open();

                var repository = new ExtendedPropertyRepository(connection);

                repository.UpdateExtendedProperty(new ExtendedProperty(name, "schema", table.Schema, "table", table.Name)
                {
                    Value = value
                });

                table.Description = value;
            }
        }