ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data.Knowledge Namespace / KnowledgeGraphQueryFilter Class / BindParameters Property
Example

In This Topic
    BindParameters Property
    In This Topic
    Gets the query bind parameter collection. The collection is a KnowledgeGraphObjectValue. This property must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public KnowledgeGraphObjectValue BindParameters {get;}
    Public ReadOnly Property BindParameters As KnowledgeGraphObjectValue
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    BindParameter keys in the collection must be unique. Specifying a key name for a key that already exists will overwrite the existing key value. Key names should match bind parameter names in the query (minus the "$" prefix). Lists of values must be stored in a KnowledgeGraphArrayValue. Generic .NET Lists and arrays cannot be used directly.
    Example
    Use Bind Parameters with an Open Cypher Query
    QueuedTask.Run(async () =>
    {
      //assume we have, in this case, a list of ids (perhaps retrieved
      //via a selection, hardcoded (like here), etc.
      var oids = new List<long>() { 3,4,7,8,9,11,12,14,15,19,21,25,29,
          31,32,36,37,51,53,54,55,56,59,63,75,78,80,84,86,88,96,97,98,101,
          103,106};
      //In the query, we refer to the "bind parameter" with the
      //"$" and a variable name - '$object_ids' in this example
      var qry = @"MATCH (p:PhoneNumber) " +
                @" WHERE p.objectid IN $object_ids " +
                @"RETURN p";
    
      //we provide the values to be substituted for the variable via the
      //KnowledgeGraphQueryFilter BindParameter property...
      var kg_qry_filter = new KnowledgeGraphQueryFilter()
      {
        QueryText = qry
      };
      //the bind parameter added to the query filter must refer to
      //the variable name used in the query string (without the "$")
      //Note:
      //Collections must be converted to a KnowledgeGraphArrayValue before
      //being assigned to a BindParameter
      var kg_oid_array = new KnowledgeGraphArrayValue();
      kg_oid_array.AddRange(oids);
      oids.Clear();
    
      kg_qry_filter.BindParameters["object_ids"] = kg_oid_array;
    
      //submit the query
      using (var kgRowCursor = kg.SubmitQuery(kg_qry_filter))
      {
        //wait for rows to be returned asynchronously from the server
        while (await kgRowCursor.WaitForRowsAsync())
        {
          //get the rows using "standard" move next
          while (kgRowCursor.MoveNext())
          {
            //current row is accessible via ".Current" prop of the cursor
            using (var graphRow = kgRowCursor.Current)
            {
              var cell_phone = graphRow[0] as KnowledgeGraphEntityValue;
              var oid = cell_phone.GetObjectID();
    
              var name = (string)cell_phone["FULL_NAME"];
              var ph_number = (string)cell_phone["PHONE_NUMBER"];
              System.Diagnostics.Debug.WriteLine(
                $"[{oid}] {name}, {ph_number}");
            }
          }
        }
      }
    });
    
    Use Bind Parameters with an Open Cypher Query2
    QueuedTask.Run(async () =>
    {
      //assume we have, in this case, a list of ids (perhaps retrieved
      //via a selection, hardcoded (like here), etc.
      var oids = new List<long>() { 3,4,7,8,9,11,12,14,15,19,21,25,29,
          31,32,36,37,51,53,54,55,56,59,63,75,78,80,84,86,88,96,97,98,101,
          103,106};
      //In the query, we refer to the "bind parameter" with the
      //"$" and a variable name - '$object_ids' and '$sel_geom'
      //in this example
      var qry = @"MATCH (p:PhoneNumber) " +
                  @"WHERE p.objectid IN $object_ids AND " +
                  @"esri.graph.ST_Intersects($sel_geom, p.shape) " +
                  @"RETURN p";
      //create a KG query filter
      var kg_qry_filter = new KnowledgeGraphQueryFilter()
      {
        QueryText = qry
      };
    
      //the bind parameter added to the query filter must refer to
      //the variable name used in the query string (without the "$")
      //Note:
      //Collections must be converted to a KnowledgeGraphArrayValue before
      //being assigned to a BindParameter
      var kg_oid_array = new KnowledgeGraphArrayValue();
      kg_oid_array.AddRange(oids);
      kg_qry_filter.BindParameters["object_ids"] = kg_oid_array;
      kg_qry_filter.BindParameters["sel_geom"] = poly;
      oids.Clear();
    
      //submit the query
      using (var kgRowCursor = kg.SubmitQuery(kg_qry_filter))
      {
        //wait for rows to be returned asynchronously from the server
        while (await kgRowCursor.WaitForRowsAsync())
        {
          //get the rows using "standard" move next
          while (kgRowCursor.MoveNext())
          {
            //current row is accessible via ".Current" prop of the cursor
            using (var graphRow = kgRowCursor.Current)
            {
              #region Process Row
    
              var cell_phone = graphRow[0] as KnowledgeGraphEntityValue;
              var oid = cell_phone.GetObjectID();
    
              var name = (string)cell_phone["FULL_NAME"];
              var ph_number = (string)cell_phone["PHONE_NUMBER"];
              System.Diagnostics.Debug.WriteLine(
                $"[{oid}] {name}, {ph_number}");
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.3 or higher.
    See Also