Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new filtered model by copying elements from an existing model
        /// </summary>
        public TSqlModel CreateFilteredModel(TSqlModel model)
        {
            // CloneModelOptions copies the database options of the existing model so that it can be used during
            // model creation
            TSqlModelOptions options = model.CloneModelOptions();

            TSqlModel filteredModel = new TSqlModel(model.Version, options);

            // A call to GetObjects with no ModelTypeClasses specified returns all top-level objects.
            // These are objects such as Tables, Views, Indexes - anything that can be defined by itself in TSQL.
            // Examples of non-top level objects are Columns.
            IEnumerable <TSqlObject> allObjects = model.GetObjects(QueryScopes);

            // Filter the objects and copy them to the new model.
            // Note that some objects such as DatabaseOptions, and any inlined constraints, will
            // not support being scripted out. DatabaseOptions don't get a TSQL representation (hence the clone method),
            // and inline constraints get scripted out with table/view definitions so to avoid duplication errors they
            // can't be scripted
            IFilter allFilters = new CompositeFilter(_filters);

            foreach (TSqlObject tsqlObject in allFilters.Filter(allObjects))
            {
                string script;
                if (tsqlObject.TryGetScript(out script))
                {
                    // Some objects such as the DatabaseOptions can't be scripted out.
                    filteredModel.AddObjects(script);
                }
            }

            return(filteredModel);
        }
Ejemplo n.º 2
0
        public void Remove(IEnumerable <string> objectNames)
        {
            var options  = SqlModel.CloneModelOptions();
            var newModel = new TSqlModel(SqlModel.Version, options);

            foreach (var obj in SqlModel.GetObjects(DacQueryScopes.UserDefined).Where(o => !o.Name.HasName || !objectNames.Contains(o.Name.ToString())))
            {
                if (obj.TryGetScript(out var script))
                {
                    newModel.AddObjects(script);
                }
                else
                {
                    _logger.Debug("Remove - Unable to get script from SQL object {Name} {Type}", obj.Name, obj.ObjectType.Name);
                }
            }

            lock (SqlModel)
            {
                SqlModel?.Dispose();
                SqlModel = newModel;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a new filtered model by copying elements from an existing model
        /// </summary>
        public TSqlModel CreateFilteredModel(TSqlModel model)
        {
            // CloneModelOptions copies the database options of the existing model so that it can be used during
            // model creation
            TSqlModelOptions options = model.CloneModelOptions();

            TSqlModel filteredModel = new TSqlModel(model.Version, options);

            // A call to GetObjects with no ModelTypeClasses specified returns all top-level objects.
            // These are objects such as Tables, Views, Indexes - anything that can be defined by itself in TSQL.
            // Examples of non-top level objects are Columns.
            IEnumerable<TSqlObject> allObjects = model.GetObjects(QueryScopes);

            // Filter the objects and copy them to the new model.
            // Note that some objects such as DatabaseOptions, and any inlined constraints, will
            // not support being scripted out. DatabaseOptions don't get a TSQL representation (hence the clone method),
            // and inline constraints get scripted out with table/view definitions so to avoid duplication errors they
            // can't be scripted
            IFilter allFilters = new CompositeFilter(_filters);
            foreach (TSqlObject tsqlObject in allFilters.Filter(allObjects))
            {
                string script;
                if (tsqlObject.TryGetScript(out script))
                {
                    // Some objects such as the DatabaseOptions can't be scripted out.
                    filteredModel.AddObjects(script);
                }
            }

            return filteredModel;
        }