Enable scripting for subobjects such as triggers (#1237)

* WIP 1

* Cleanups

* Change how schema is appended in to urn

* Add comment and fix incorrect condition

* Add parent type name to support Views, etc.
This commit is contained in:
Karl Burtram
2021-08-26 13:06:15 -07:00
committed by GitHub
parent 0421d3ae7c
commit 5d5debbad6
4 changed files with 75 additions and 19 deletions

View File

@@ -4,6 +4,7 @@
//
using System.Globalization;
using Microsoft.SqlServer.Management.Sdk.Sfc;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes;
@@ -56,13 +57,13 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
{
SmoObject = smoObject;
NodeValue = smoObject.Name;
ScriptSchemaObjectBase schemaBasecObject = smoObject as ScriptSchemaObjectBase;
ScriptSchemaObjectBase schemaBaseObject = smoObject as ScriptSchemaObjectBase;
ObjectMetadata = new Metadata.Contracts.ObjectMetadata();
ObjectMetadata.Name = smoObject.Name;
try
{
if(smoObject.Urn != null)
if (smoObject.Urn != null)
{
ObjectMetadata.MetadataTypeName = smoObject.Urn.Type;
}
@@ -72,16 +73,27 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel
//Ignore the exception, sometimes the urn returns exception and I' not sure why
}
if (schemaBasecObject != null)
if (schemaBaseObject != null)
{
ObjectMetadata.Schema = schemaBasecObject.Schema;
ObjectMetadata.Schema = schemaBaseObject.Schema;
if (!string.IsNullOrEmpty(ObjectMetadata.Schema))
{
NodeValue = $"{ObjectMetadata.Schema}.{smoObject.Name}";
}
}
else
{
// Try to read the schema from the parent object
var parent = smoObject?.ParentCollection?.ParentInstance as ScriptSchemaObjectBase;
if (parent != null)
{
ObjectMetadata.Schema = parent.Schema;
ObjectMetadata.ParentName = parent.Name;
ObjectMetadata.ParentTypeName = parent.Urn.Type;
}
}
}
public virtual NamedSmoObject GetParentSmoObject()
{
if (SmoObject != null)