mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-17 01:25:40 -05:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user