@@ -71,7 +71,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
7171 WriteLine("{");
7272 PushIndent(indent);
7373
74- string navigationPath = GetNavigationPath(nodeElement, xmlFile, nodeName, parentType);
74+ XmlElement navPathElement = GetNavPathElement(xmlFile, nodeName, parentType);
75+ string navigationPath = GetNavigationPath(nodeElement, nodeName, navPathElement);
76+ string subField = GetNavPathAttribute(navPathElement, "SubField");
77+ string fieldType = GetNavPathAttribute(navPathElement, "FieldType");
7578
7679
7780 WriteLine(string.Format("var retValue = {0}.{1};", parentVar, navigationPath));
@@ -83,7 +86,27 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
8386 if (IsCollection(nodeElement))
8487 {
8588 WriteLine(string.Format("retValue.ClearAndInitialize(filter, extraProperties);"));
86- WriteLine(string.Format("return new SmoCollectionWrapper<{0}>(retValue).Where(c => PassesFinalFilters({1}, c));", nodeType, parentVar));
89+ if (string.IsNullOrEmpty(subField) )
90+ {
91+ WriteLine(string.Format("return new SmoCollectionWrapper<{0}>(retValue).Where(c => PassesFinalFilters({1}, c));", nodeType, parentVar));
92+ }
93+ else
94+ {
95+ WriteLine(string.Format("List<{0}> subFieldResult = new List<{0}>();", nodeType));
96+ WriteLine(string.Format("foreach({0} field in retValue)", fieldType));
97+ WriteLine("{");
98+ PushIndent(indent);
99+ WriteLine(string.Format("{0} subField = field.{1};", nodeType, subField));
100+ WriteLine(string.Format("if (subField != null)"));
101+ WriteLine("{");
102+ PushIndent(indent);
103+ WriteLine(string.Format("subFieldResult.Add(subField);"));
104+ PopIndent();
105+ WriteLine("}");
106+ PopIndent();
107+ WriteLine("}");
108+ WriteLine(string.Format("return subFieldResult.Where(c => PassesFinalFilters({1}, c));", nodeType, parentVar));
109+ }
87110 }
88111 else
89112 {
@@ -142,27 +165,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
142165 return (XmlElement)doc.SelectSingleNode(string.Format("/SmoQueryModel/Node[@Name='{0}']", nodeName));
143166 }
144167
145- public static string GetNavPathField (string xmlFile, string nodeName, string parent)
168+ public static XmlElement GetNavPathElement (string xmlFile, string nodeName, string parent)
146169 {
147170 XmlDocument doc = new XmlDocument();
148171 doc.Load(xmlFile);
149172 XmlElement navPathElement = (XmlElement)doc.SelectSingleNode(string.Format("/SmoQueryModel/Node[@Name='{0}']/NavigationPath[@Parent='{1}']", nodeName, parent));
150173
151- return navPathElement == null ? null : navPathElement.GetAttribute("Field") ;
174+ return navPathElement;
152175 }
153176
154- public static string GetNavPathFieldForUrn(string xmlFile , string nodeName, string parent )
177+ public static string GetNavPathAttribute(XmlElement navPathElement , string attributeName )
155178 {
156- XmlDocument doc = new XmlDocument();
157- doc.Load(xmlFile);
158- XmlElement navPathElement = (XmlElement)doc.SelectSingleNode(string.Format("/SmoQueryModel/Node[@Name='{0}']/NavigationPath[@Parent='{1}']", nodeName, parent));
159-
160- return navPathElement == null ? null : navPathElement.GetAttribute("FieldForUrn");
179+ return navPathElement == null ? null : navPathElement.GetAttribute(attributeName);
161180 }
162181
163- public static string GetNavigationPath(XmlElement nodeElement, string xmlFile, string nodeName, string parentName )
182+ public static string GetNavigationPath(XmlElement nodeElement, string nodeName, XmlElement navPathElement )
164183 {
165- string navPathField = GetNavPathField(xmlFile, nodeName, parentName );
184+ string navPathField = GetNavPathAttribute(navPathElement, "Field" );
166185 if (!string.IsNullOrEmpty(navPathField))
167186 {
168187 return navPathField;
0 commit comments