ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data.Knowledge Namespace / KnowledgeGraph Class / KnowledgeGraph Constructor
A valid KnowledgeGraphConnectionProperties object which has the URI to the knowledge graph service or path to a file-based knowledge graph.
Example

In This Topic
    KnowledgeGraph Constructor
    In This Topic
    Opens a knowledge graph datastore with a KnowledgeGraphConnectionProperties. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax

    Parameters

    connectionProperties
    A valid KnowledgeGraphConnectionProperties object which has the URI to the knowledge graph service or path to a file-based knowledge graph.
    Exceptions
    ExceptionDescription
    The information used to connect to the knowledge graphic service is invalid.
    This method or property must be called within the lambda passed to QueuedTask.Run.
    The connection properties or URL is not provided.
    Example
    Opening a Connection to a KnowledgeGraph
    {
      await QueuedTask.Run(() =>
      {
        //Create a connection properties
        var kg_props =
            new KnowledgeGraphConnectionProperties(new Uri(url));
        try
        {
          //Open a connection
          using (var kg = new KnowledgeGraph(kg_props))
          {
            //TODO...use the KnowledgeGraph
          }
        }
        catch (GeodatabaseNotFoundOrOpenedException ex)
        {
          System.Diagnostics.Debug.WriteLine(ex.ToString());
        }
      });
    }
    Opening a Connection to a File KnowledgeGraph
    {
      await QueuedTask.Run(() =>
      {
        //Starting at 3.7, users can connect to a _file_ knowledge graph
        //The extension for a file kg is ".knowledgegraph"
        // Any path you want
        string kgPath = @"C:\Data\KG\Filebased_KG";
        string kgFileName = @"Test_File_KG.knowledgegraph";
    
        var kg_full_path = System.IO.Path.Combine(kgPath, kgFileName);
    
        var kg_props = new KnowledgeGraphConnectionProperties(new Uri(kg_full_path));
        try
        {
          //Open a connection
          using (var kg = new KnowledgeGraph(kg_props))
          {
            //TODO...use the File KnowledgeGraph
            var i = 0;
            //Get the featureclass definitions from the KG datastore
            var fc_defs = kg.GetDefinitions<FeatureClassDefinition>();
            //For each feature class definition, get the corresponding
            //feature class. Note: The name of the feature class will match 
            //the name of its corresponding KnowledgeGraph named object type
            //in the KnowledgeGraph graph data model
            foreach (var fc_def in fc_defs)
            {
              var fc_name = fc_def.GetName();
              System.Diagnostics.Debug.WriteLine($"FeatureClass[{i++}] {fc_name}");
            }
          }
        }
        catch (GeodatabaseNotFoundOrOpenedException ex)
        {
          System.Diagnostics.Debug.WriteLine(ex.ToString());
        }
      });
    }
    Retrieving GDB FeatureClasses and Definitions
    {
      await QueuedTask.Run(() =>
      {
        //Create a connection properties
        var kg_props =
            new KnowledgeGraphConnectionProperties(new Uri(url));
        //Connect to the KnowledgeGraph datastore
        //KnowledgeGraph datastores contain tables and feature classes
        using (var kg = new KnowledgeGraph(kg_props))
        {
          //Get the featureclass definitions from the KG datastore
          var fc_defs = kg.GetDefinitions<FeatureClassDefinition>();
          //For each feature class definition, get the corresponding
          //feature class. Note: The name of the feature class will match 
          //the name of its corresponding KnowledgeGraph named object type
          //in the KnowledgeGraph graph data model
          foreach (var fc_def in fc_defs)
          {
            var fc_name = fc_def.GetName();
            using (var fc = kg.OpenDataset<FeatureClass>(fc_name))
            {
              //TODO - use the feature class
            }
          }
        }
      });
    }
    Retrieving GDB Tables and Definitions
    {
      QueuedTask.Run(() =>
      {
        //Create a connection properties
        var kg_props =
            new KnowledgeGraphConnectionProperties(new Uri(url));
        //Connect to the KnowledgeGraph datastore
        //KnowledgeGraph datastores contain tables and feature classes
        using (var kg = new KnowledgeGraph(kg_props))
        {
          //Get the table definitions from the KG datastore
          var tbl_defs = kg.GetDefinitions<TableDefinition>();
          //For each table definition, get the corresponding
          //table. Note: The name of the table will match the name
          //of its corresponding KnowledgeGraph named object type in
          //the KnowledgeGraph graph data model
          foreach (var tbl_def in tbl_defs)
          {
            var tbl_name = tbl_def.GetName();
            using (var fc = kg.OpenDataset<Table>(tbl_name))
            {
              //TODO - use the table
            }
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.2 or higher.
    See Also