SMO Scripting \ Filtering Dependencies
-
Friday, December 09, 2011 5:23 PM
I am scripting out a bunch of dependencies based on a table object. I can get the dependencies and script them no problem. The problem is I need to (or would like to) filter out the dependencies (nodes) that are not in DependencyTree.FirstChild. I don't nned the other nodes. I can't seem to find any examples of code to help me with this.
Thanks Mike
All Replies
-
Monday, December 12, 2011 3:01 AMModerator
Hi mdmck,
To remove the Dependency Tree Nodes which is not the FirstChild, you can use FirstChild and NextSibling properties to navigate to the target node, and use Remove method to remove this node.
For more information, please refer to: DependencyTree Class.If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
Stephanie Lv
TechNet Community Support
-
Wednesday, December 14, 2011 3:57 PM
Thanks Stephanie. I understand those properties...I just can't seem to get it to work...I have 400 sibling nodes I can get to the next one but only once...if you have any code examples...I don't see any pertinent ones in the any of the online help sites...
Thanks Mike
-
Thursday, December 15, 2011 1:30 AMModerator
Hi Mike,
Could you please pay attention to this article Scripting?
After Discovery is finished, the user has a chance to manipulate the dependency tree and remove unnecessary branches for objects that do not need to be scripted. The user can navigate the dependency tree in a simple manner. Each node in a tree is represented by the DependencyTreeNode object, which can have any number of dependent child nodes. You can walk through each level of dependent child objects as follows:If (depParent.HasChildNodes) { depChild = depParent.FirstChild; while ( null != depChild ) { // do something with the node depChild = depChild.NextSibling; } }While navigating the tree, you can remove any of its branches by calling the Remove method on any node. This causes the particular node and any of its dependent nodes to not be scripted.
Stephanie Lv
TechNet Community Support
- Edited by Stephanie LvModerator Thursday, December 15, 2011 1:31 AM
- Marked As Answer by Stephanie LvModerator Tuesday, December 20, 2011 11:45 AM

