ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Data Namespace / QueryFilter Class / SubFields Property
Example

In This Topic
    SubFields Property (QueryFilter)
    In This Topic
    Gets or sets a comma (,) delimited string containing the names of fields for which values should be returned by the query.
    Syntax
    public string SubFields {get; set;}
    Public Property SubFields As String
    Remarks

    The subfield property requests a minimum set of fields to return values for, by restricting the set of fields for which values are returned you can optimize the performance of the query when using a query filter. Additional values may be returned for fields that the query requires (e.g., ObjectID or Shape fields). Fields not included in the subfields list or required by the query are still present in the rows returned, but are not populated with values. Including all of the fields in the row ensures that the field index position is constant no matter how it was hydrated.

    The default setting for subfields is to request values to be returned for all fields. The strings of "*" or "" can be set to return the query to this default. The default of returning all fields should always be used if the intent of the operation is to alter the values of the row and store it.

    To set the subfields property to request the values to be returned for the "Name" and "Age" fields a string of "Name, Age" should be provided (white space is optional).

    It is not required to set the subfields property if the query filter is to be used in a context where no rows are returned (e.g., Table.Select).

    Example
    Searching a Table using QueryFilter
    public async Task SearchingATable()
    {
      try
      {
        await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
        {
          using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
          using (Table table = geodatabase.OpenDataset<Table>("EmployeeInfo"))
          {
    
            QueryFilter queryFilter = new QueryFilter
            {
              WhereClause = "COSTCTRN = 'Information Technology'",
              SubFields = "KNOWNAS, OFFICE, LOCATION",
              PostfixClause = "ORDER BY OFFICE"
            };
    
            using (RowCursor rowCursor = table.Search(queryFilter, false))
            {
              while (rowCursor.MoveNext())
              {
                using (Row row = rowCursor.Current)
                {
                  string location = Convert.ToString(row["LOCATION"]);
                  string knownAs = Convert.ToString(row["KNOWNAS"]);
                }
              }
            }
          }
        });
      }
      catch (GeodatabaseFieldException fieldException)
      {
        // One of the fields in the where clause might not exist. There are multiple ways this can be handled:
        // Handle error appropriately
      }
      catch (Exception exception)
      {
        // logger.Error(exception.Message);
      }
    }
    Use Select or Search with a Spatial Query
    //var featSceneLayer = ...;
    //var sname = featSceneLayer.Name;
    await QueuedTask.Run(() =>
    {
      if (!featSceneLayer.HasAssociatedFeatureService)
        return;//no search or select
    
      //Select all features within the current map view
      var sz = MapView.Active.GetViewSize();
      var map_pt1 = MapView.Active.ClientToMap(new System.Windows.Point(0, sz.Height));
      var map_pt2 = MapView.Active.ClientToMap(new System.Windows.Point(sz.Width, 0));
    
      //Convert to an envelope
      var temp_env = EnvelopeBuilderEx.CreateEnvelope(map_pt1, map_pt2, MapView.Active.Map.SpatialReference);
    
      //Project if needed to the layer spatial ref
      SpatialReference sr = null;
      using (var fc = featSceneLayer.GetFeatureClass())
      using (var fdef = fc.GetDefinition())
        sr = fdef.GetSpatialReference();
    
      var env = GeometryEngine.Instance.Project(temp_env, sr) as Envelope;
    
      //Set up a query filter
      var sf = new SpatialQueryFilter()
      {
        FilterGeometry = env,
        SpatialRelationship = SpatialRelationship.Intersects,
        SubFields = "*"
      };
    
      //Select against the feature service
      var select = featSceneLayer.Select(sf);
      if (select.GetCount() > 0)
      {
        //enumerate over the selected features
        using (var rc = select.Search())
        {
          while (rc.MoveNext())
          {
            using (var feature = rc.Current as Feature)
            {
              var oid = feature.GetObjectID();
              //etc.
            }
          }
        }
      }
    
      MapView.Active.Map.ClearSelection();
    
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also