<?xml version="1.0" encoding="utf-8" ?>
<!--
  This XML file defines how to query for a given SMO type based on a parent/child or
  XPath relationship. From this file, the paths to query each type should be buildable
  into code using a T4 template.
  
  Key properties:
  attr.Name: This maps 
  attr.Type: Optional SMO type. If not specified, the Name without the Sql prefix is used
  attr.Parent: Expected parent type. Needed to codegen the response.
  Parent: In case a node has multiple parents, chilren of type parents need to be added. 
    Each parent should have corresponding navigation path.
  NavigationPath: For types whose access path differs based on parent or needs custom navigation
    this can be used.
    attr.Parent: The parent type that this navigation path is valid for
    attr.Field: The field to use to navigate to the child type
    Filter: Optional filter to apply to the navigation path. This is used to filter out
      results that are not of the expected type. For example, the SqlTable type has a
      filter on the Schema field to ensure that the table is in the expected schema.
      attr.Property: The property to filter on
      attr.Field: The field to use from the parent to filter on the property
      attr.Type: The type of the field.
-->
<SmoQueryModel>
  <!--<Node Name="SqlServer"/> -->
  <Node Name="SqlDatabase" Type="Database" Parent="Server" />
  <Node Name="SqlLinkedServerLogin" Type="LinkedServer" Parent="Server"/>
  <Node Name="SqlLogin" Type="Login" Parent="Server" />
  <Node Name="SqlServerRole" Type="" Parent="Server" >
    <NavigationPath Parent="Server" Field="Roles" />
  </Node>
  
  <Node Name="SqlCredential" Parent="Server" />
  <Node Name="SqlCryptographicProvider" Parent="Server" />
  <Node Name="SqlServerAudit" Type="Audit" Parent="Server" />
  <Node Name="SqlServerAuditSpecification" Type="ServerAuditSpecification" Parent="Server"/>
  
  <Node Name="SqlEndpoint" Parent="Server"/>
  <Node Name="SqlLinkedServer" Parent="Server" />
  <Node Name="SqlServerDdlTrigger" Parent="Server" ValidFor="NotSqlDw" >
    <NavigationPath Parent="Server" Field="Triggers" />
  </Node>

  <Node Name="SqlErrorMessage" Type="UserDefinedMessage" Parent="Server" />

  <Node Name="SqlTable">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="Tables" />
    <NavigationPath Parent="Schema" Field="Parent.Tables">
      <Filter Property="Schema" Field="Name" Type="string" />
    </NavigationPath>
  </Node>

  
  <Node Name="SqlHistoryTable" Type="Table" Parent="Table" >
    <NavigationPath Parent="Table" Type="Table" Field="Parent.Tables" />
  </Node>
  
  <Node Name="SqlView">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="Views" />
    <NavigationPath Parent="Schema" Field="Parent.Views">
      <Filter Property="Schema" Field="Name" Type="string" />
    </NavigationPath>
  </Node>

  <Node Name="SqlSynonym" ValidFor="NotSqlDw">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="Synonyms" />
    <NavigationPath Parent="Schema" Field="Parent.Synonyms">
      <Filter Property="Schema" Field="Name" Type="string" />
    </NavigationPath>
  </Node>

  <Node Name="SqlColumn" Parent="TableViewTableTypeBase"/>
  <Node Name="SqlIndex" Parent="TableViewTableTypeBase">
    <NavigationPath Parent="TableViewTableTypeBase" Field="Indexes" />
  </Node>

  <Node Name="SqlCheck" Parent="Table"/>
  <Node Name="SqlForeignKeyConstraint" Type="ForeignKey" Parent="Table" />
  <Node Name="SqlDefaultConstraint" Collection="True" >
    <Parent>Table</Parent>
    <Parent>UserDefinedTableType</Parent>
    <NavigationPath Parent="Table" Field="Columns" SubField="DefaultConstraint" FieldType="Column" />
    <NavigationPath Parent="UserDefinedTableType" Field="Columns" SubField="DefaultConstraint" FieldType="Column" />
  </Node>
  <Node Name="SqlDmlTrigger" Type="Trigger" ValidFor="NotSqlDw">
    <Parent>Table</Parent>
    <Parent>View</Parent>
  </Node>
  <Node Name="SqlFullTextIndex" Parent="Table" Collection="False" ValidFor="NotSqlDw" />
  <Node Name="SqlStatistic" Parent="TableViewBase"/>

  <Node Name="SqlDatabaseDdlTrigger" Type="DatabaseDdlTrigger" Parent="Database" ValidFor="NotSqlDw">
    <NavigationPath Parent="Database" Field="Triggers" />
  </Node>
  <Node Name="SqlAssembly" Type="SqlAssembly" Parent="Database" >
    <NavigationPath Parent="Database" Field="Assemblies" />
  </Node>

  <!-- Deprecated
  <Node Name="SqlRule" Parent="Database" />
  <Node Name="SqlDefault" Parent="Database" />
  -->
  <Node Name="SqlSequence">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="Sequences" />
    <NavigationPath Parent="Schema" Field="Parent.Sequences">
        <Filter Property="Schema" Field="Name" Type="string"/>
    </NavigationPath>
  </Node>

  <Node Name="SqlUserDefinedDataType" ValidFor="NotSqlDw">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="UserDefinedDataTypes" />
    <NavigationPath Parent="Schema" Field="Parent.UserDefinedDataTypes">
        <Filter Property="Schema" Field="Name" Type="string"/>
    </NavigationPath>
  </Node>

  <Node Name="SqlUserDefinedTableType">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="UserDefinedTableTypes" />
    <NavigationPath Parent="Schema" Field="Parent.UserDefinedTableTypes">
        <Filter Property="Schema" Field="Name" Type="string"/>
    </NavigationPath>
  </Node>

  <Node Name="SqlXmlSchemaCollection">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="XmlSchemaCollections" />
    <NavigationPath Parent="Schema" Field="Parent.XmlSchemaCollections">
        <Filter Property="Schema" Field="Name" Type="string"/>
    </NavigationPath>
  </Node>

  <Node Name="SqlUserDefinedType">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="UserDefinedTypes" />
    <NavigationPath Parent="Schema" Field="Parent.UserDefinedTypes">
        <Filter Property="Schema" Field="Name" Type="string"/>
    </NavigationPath>
  </Node>

  <Node Name="SqlUserDefinedFunction">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <Navigation Path="Database" Field="UserDefinedFunctions" />
    <NavigationPath Parent="Schema" Field="Parent.UserDefinedFunctions">
      <Filter Property="Schema" Field="Name" Type="string"/>
  </NavigationPath>
  </Node>

  <Node Name="SqlUserDefinedAggregate">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="UserDefinedAggregates" />
    <NavigationPath Parent="Schema" Field="Parent.UserDefinedAggregates">
        <Filter Property="Schema" Field="Name" Type="string"/>
    </NavigationPath>
  </Node>

  <Node Name="SqlFileGroup" />
  <Node Name="SqlFile" Type="DataFile" Parent="FileGroup" >
    <NavigationPath Parent="FileGroup" Field="Files" />
  </Node>
  
  <Node Name="SqlFullTextCatalog"/>
  <Node Name="SqlFullTextStopList" />
  <Node Name="SqlPartitionFunction"/>
  <Node Name="SqlPartitionScheme"/>
  <Node Name="SqlSearchPropertyList" />
  <Node Name="SqlUser"/>
  <Node Name="SqlSchema"/>
  <Node Name="SqlAsymmetricKey" />
  <Node Name="SqlCertificate" />
  <Node Name="SqlSymmetricKey" />
  <Node Name="SqlDatabaseEncryptionKey" Collection="False" />
  <Node Name="SqlMasterKey" Collection="False" />
  <Node Name="SqlDatabaseAuditSpecification" />
  <Node Name="SqlSecurityPolicy" >
    <NavigationPath Parent="Database" Field="SecurityPolicies" />
  </Node>
  <Node Name="SqlDatabaseCredential" Type="DatabaseScopedCredential"/>
  <Node Name="SqlRole" Type="DatabaseRole" >
    <NavigationPath Parent="Database" Field="Roles" />
  </Node>
  <Node Name="SqlApplicationRole" />
  <Node Name="SqlColumnMasterKey" />
  <Node Name="SqlColumnEncryptionKey" />
  
  <Node Name="SqlServiceBroker" Type="ServiceBroker" Collection="False" />
  <Node Name="SqlService" Type="BrokerService" Parent="ServiceBroker" >
    <NavigationPath Parent="ServiceBroker" Field="Services" />
  </Node>
  -
  <Node Name="SqlContract" Type="ServiceContract" Parent="ServiceBroker" />
  <Node Name="SqlQueue" Type="ServiceQueue" Parent="ServiceBroker" >
    <NavigationPath Parent="ServiceBroker" Field="Queues" />
  </Node>
  <Node Name="SqlRemoteServiceBinding" Parent="ServiceBroker" />
  <Node Name="SqlBrokerPriority" Parent="ServiceBroker" >
    <NavigationPath Parent="ServiceBroker" Field="Priorities" />
  </Node>
  
  <Node Name="SqlMessageType" Parent="ServiceBroker"/>
  
  <Node Name="SqlExternalDataSource" />
  <Node Name="SqlExternalFileFormat" />

  <Node Name="SqlProcedure" Type="StoredProcedure">
    <Parent>Database</Parent>
    <Parent>Schema</Parent>
    <NavigationPath Parent="Database" Field="StoredProcedures" />
    <NavigationPath Parent="Schema" Field="Parent.StoredProcedures">
        <Filter Property="Schema" Field="Name" Type="string"/>
    </NavigationPath>
  </Node>
  <Node Name="SqlExtendedStoredProcedure" />
  <Node Name="SqlSubroutineParameter" Type="Parameter" >
    <Parent>StoredProcedure</Parent>
    <Parent>UserDefinedAggregate</Parent>
    <Parent>UserDefinedFunction</Parent>
  </Node>

  <Node Name="SqlPartitionFunctionParameter" Parent="PartitionFunction" />

  <Node Name="SqlBuiltInType" Type="SystemDataType" Parent="Database">
    <NavigationPath Parent="Database" Field="Parent.SystemDataTypes" FieldForUrn="Parent" />
  </Node>
  <!-- TODO Enable all types
  <Node Name="SqlRoute"/>
  -->
  <!-- Signatures appear to be missing entirely from SMO and SSMS object explorer...
  <Node Name="SqlSignature" />
  -->
  <!-- TODO find mapping - exists in SSDT but not SSMS / SMO?
  <Node Name="SqlEventNotification" Parent="ServiceBroker" />
   -->
  <!-- TODO Requires XEvents SMO DLL in .Net Core 
  <Node Name="SqlEventSession" Type="Session" />
  <Node Name="SqlServerEventNotification" Type="Event" Parent="Server" />
  -->
</SmoQueryModel>
