使用SMO的嵌套级别SQL依赖关系树

我正在使用SQL SMO在我的Windows应用程序中构建类似sql management studio依赖树的树

Server srv = new Server();
var dependencyWalker = new DependencyWalker(srv);
var dependencyTree = dependencyWalker.DiscoverDependencies(new Urn[] { srv.Databases["myDB"].Tables["Resource"].Urn }, DependencyType.Parents);
var dependencyCollection = dependencyWalker.WalkDependencies(dependencyTree);

dependencyCollection是8个DependencyCollectionNode项的扁平线性列表,我无法计算任何嵌套级别依赖项,如sql management studio依赖关系树中所示。

在此处输入图像描述

我需要获取我的数据库对象(资源)的第一级项目(Model,POP,Resource_Log,ResourceType)?

采纳答案:

使用dependencyTree。

DependencyWalker的要点是将树转换为线性列表,以便(例如)对象可以按正确的顺序创建,而不会生成错误。 看起来你不需要这个,你应该直接处理DependencyTree对象。

author: fruitbat

参考更多解答: Nested Level SQL dependency tree using SMO ,转载请保留出处使用SMO的嵌套级别SQL依赖关系树及作者信息

Statement: We respect knowledge and authors. Since the content comes from the Internet and is intended for scientific research, any reprinters should retain the author's signature and origin. If you are the author of the content and feel in dispute, please contact email: 1076545519@qq.com. We will find out the situation and deal with it in time. We sincerely thank the author for his hard work.


更多:winforms