ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / KnowledgeGraphLayer Class / GetDatastore Method
Example

In This Topic
    GetDatastore Method (KnowledgeGraphLayer)
    In This Topic
    Gets the knowledge graph datastore associated with the layer. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetDatastore() As KnowledgeGraph
    public KnowledgeGraph GetDatastore()

    Return Value

    The knowledge graph datastore associated with the layer. Returns null if the KnowledgeGraph layer is empty.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Getting a Connection from a KnowledgeGraphLayer
    {
      //var kgLayer = MapView.Active.Map.GetLayersAsFlattenedList()
      //			.OfType<KnowledgeGraphLayer>().FirstOrDefault();
    
      await QueuedTask.Run(() =>
      {
        // use the layer directly
        KnowledgeGraph datastore = kgLayer.GetDatastore();
    
        // or you can use any of the sub items since
        //KnowledgeGraphLayer is a composite layer - get the first 
        // child feature layer or standalone table
        var featlayer = kgLayer?.GetLayersAsFlattenedList()?
                        .OfType<FeatureLayer>()?.FirstOrDefault();
        KnowledgeGraph kg = null;
        if (featlayer != null)
        {
          using (var fc = featlayer.GetFeatureClass())
            kg = fc.GetDatastore() as KnowledgeGraph;
          //TODO use KnowledgeGraph
        }
        else
        {
          //try standalone table
          var stbl = kgLayer?.GetStandaloneTablesAsFlattenedList()?
                          .FirstOrDefault();
          if (stbl != null)
          {
            using (var tbl = stbl.GetTable())
              kg = tbl.GetDatastore() as KnowledgeGraph;
            //TODO use KnowledgeGraph
          }
        }
      });
    }
    Get KG Datastore
    {
      var kg_layer = MapView.Active.Map.GetLayersAsFlattenedList()
                      .OfType<KnowledgeGraphLayer>().FirstOrDefault();
      if (kg_layer == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        // get the datastore
        var kg = kg_layer.GetDatastore();
    
        // now submit a search or a query
        // kg.SubmitSearch
        // kg.SubmitQuery
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.3 or higher.
    See Also