fixed the bug with loading default constraints in oe (#582)

* fixed the bug with loading default constraints in oe
This commit is contained in:
Leila Lali
2018-02-09 08:51:41 -08:00
committed by GitHub
parent fc4282b701
commit c40c740a73
5 changed files with 80 additions and 21 deletions

View File

@@ -71,7 +71,10 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
WriteLine("{");
PushIndent(indent);
string navigationPath = GetNavigationPath(nodeElement, xmlFile, nodeName, parentType);
XmlElement navPathElement = GetNavPathElement(xmlFile, nodeName, parentType);
string navigationPath = GetNavigationPath(nodeElement, nodeName, navPathElement);
string subField = GetNavPathAttribute(navPathElement, "SubField");
string fieldType = GetNavPathAttribute(navPathElement, "FieldType");
WriteLine(string.Format("var retValue = {0}.{1};", parentVar, navigationPath));
@@ -83,7 +86,27 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
if (IsCollection(nodeElement))
{
WriteLine(string.Format("retValue.ClearAndInitialize(filter, extraProperties);"));
WriteLine(string.Format("return new SmoCollectionWrapper<{0}>(retValue).Where(c => PassesFinalFilters({1}, c));", nodeType, parentVar));
if (string.IsNullOrEmpty(subField) )
{
WriteLine(string.Format("return new SmoCollectionWrapper<{0}>(retValue).Where(c => PassesFinalFilters({1}, c));", nodeType, parentVar));
}
else
{
WriteLine(string.Format("List<{0}> subFieldResult = new List<{0}>();", nodeType));
WriteLine(string.Format("foreach({0} field in retValue)", fieldType));
WriteLine("{");
PushIndent(indent);
WriteLine(string.Format("{0} subField = field.{1};", nodeType, subField));
WriteLine(string.Format("if (subField != null)"));
WriteLine("{");
PushIndent(indent);
WriteLine(string.Format("subFieldResult.Add(subField);"));
PopIndent();
WriteLine("}");
PopIndent();
WriteLine("}");
WriteLine(string.Format("return subFieldResult.Where(c => PassesFinalFilters({1}, c));", nodeType, parentVar));
}
}
else
{
@@ -142,27 +165,23 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
return (XmlElement)doc.SelectSingleNode(string.Format("/SmoQueryModel/Node[@Name='{0}']", nodeName));
}
public static string GetNavPathField(string xmlFile, string nodeName, string parent)
public static XmlElement GetNavPathElement(string xmlFile, string nodeName, string parent)
{
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
XmlElement navPathElement = (XmlElement)doc.SelectSingleNode(string.Format("/SmoQueryModel/Node[@Name='{0}']/NavigationPath[@Parent='{1}']", nodeName, parent));
return navPathElement == null ? null : navPathElement.GetAttribute("Field");
return navPathElement;
}
public static string GetNavPathFieldForUrn(string xmlFile, string nodeName, string parent)
public static string GetNavPathAttribute(XmlElement navPathElement, string attributeName)
{
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
XmlElement navPathElement = (XmlElement)doc.SelectSingleNode(string.Format("/SmoQueryModel/Node[@Name='{0}']/NavigationPath[@Parent='{1}']", nodeName, parent));
return navPathElement == null ? null : navPathElement.GetAttribute("FieldForUrn");
return navPathElement == null ? null : navPathElement.GetAttribute(attributeName);
}
public static string GetNavigationPath(XmlElement nodeElement, string xmlFile, string nodeName, string parentName)
public static string GetNavigationPath(XmlElement nodeElement, string nodeName, XmlElement navPathElement)
{
string navPathField = GetNavPathField(xmlFile, nodeName, parentName);
string navPathField = GetNavPathAttribute(navPathElement, "Field");
if (!string.IsNullOrEmpty(navPathField))
{
return navPathField;