Пример #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);
        }
Пример #2
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;
        }