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

SubFields Property (QueryDef)
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;}
Remarks

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.

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).

Example
Evaluating a QueryDef on a Join using WHERE Clause
public async Task JoiningWithWhereQueryDef()
{
  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
  {
    using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
    {
      QueryDef municipalEmergencyFacilitiesQueryDef = new QueryDef
      {
        SubFields = "EmergencyFacility.OBJECTID, EmergencyFacility.Shape, EmergencyFacility.FACILITYID, FacilitySite.FACILITYID, FacilitySite.FCODE",
        Tables = "EmergencyFacility, FacilitySite",
        WhereClause = "EmergencyFacility.FACNAME = FacilitySite.NAME AND EmergencyFacility.JURISDICT = 'Municipal'",
      };

      using (RowCursor rowCursor = geodatabase.Evaluate(municipalEmergencyFacilitiesQueryDef, false))
      {
        while (rowCursor.MoveNext())
        {
          using (Row row = rowCursor.Current)
          {
            Feature feature = row as Feature;
            Geometry shape = feature.GetShape();

            long objectID = Convert.ToInt64(row["EmergencyFacility.OBJECTID"]);
            String featureCode = Convert.ToString(row["FacilitySite.FCODE"]);

            IReadOnlyList<Field> fields = feature.GetFields(); //Contains one ArcGIS.Core.Data.Field objects for every subfield
          }
        }
      }
    }
  });
}
Evaluating a QueryDef on a OUTER JOIN
public async Task EvaluatingQueryDefWithOuterJoin()
{
  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
  {
    using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
    {
      QueryDef queryDefWithLeftOuterJoin = new QueryDef
      {
        Tables = "CommunityAddress LEFT OUTER JOIN MunicipalBoundary on CommunityAddress.Municipality = MunicipalBoundary.Name",
        SubFields = "CommunityAddress.OBJECTID, CommunityAddress.Shape, CommunityAddress.SITEADDID, CommunityAddress.ADDRNUM, CommunityAddress.FULLNAME, CommunityAddress.FULLADDR, CommunityAddress.MUNICIPALITY, MunicipalBoundary.Name, MunicipalBoundary.MUNITYP, MunicipalBoundary.LOCALFIPS",
      };

      using (RowCursor rowCursor = geodatabase.Evaluate(queryDefWithLeftOuterJoin, false))
      {
        while (rowCursor.MoveNext())
        {
          using (Row row = rowCursor.Current)
          {
            Feature feature = row as Feature;
            Geometry shape = feature.GetShape();

            int siteAddressId = Convert.ToInt32(row["CommunityAddress.SITEADDID"]);
            String stateName = Convert.ToString(row["MunicipalBoundary.name"]);
          }
        }
      }
    }
  });
}
Evaluating a QueryDef on a INNER join
public async Task EvaluatingQueryDefWithInnerJoin()
{
  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
  {
    using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
    {
      QueryDef queryDef = new QueryDef()
      {
        Tables = "People INNER JOIN States ON People.FK_STATE_ID = States.OBJECTID",
        SubFields = "People.OBJECTID, People.First_Name, People.Last_Name, People.City, States.State_Name"
      };

      using (RowCursor cursor = geodatabase.Evaluate(queryDef))
      {
        while (cursor.MoveNext())
        {
          using (Row row = cursor.Current)
          {
            // Handle row
          }
        }
      }
    }
  });
}
Evaluating a QueryDef on a nested - INNER and OUTER join
public async Task EvaluatingQueryDefWithNestedJoin()
{
  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
  {
    using (Geodatabase geodatabase = new Geodatabase(
      new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
    {
      QueryDef queryDef = new QueryDef()
      {
        Tables = "((People INNER JOIN States ON People.FK_STATE_ID = States.OBJECTID) LEFT OUTER JOIN Homes ON People.OBJECTID = Homes.FK_People_ID)",
        SubFields = "People.OBJECTID, People.First_Name, People.Last_Name, States.State_Name, Homes.Address"
      };

      using (RowCursor cursor = geodatabase.Evaluate(queryDef, false))
      {
        while (cursor.MoveNext())
        {
          using (Row row = cursor.Current)
          {
            // Handle row
          }
        }
      }
    }
  });
}
Creating a QueryTable using a query which joins two versioned tables in a geodatabase
public async Task QueryTableJoinWithVersionedData()
{
  await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
  {
    QueryDef queryDef = new QueryDef
    {
      Tables = "CommunityAddress JOIN MunicipalBoundary on CommunityAddress.Municipality = MunicipalBoundary.Name",
      SubFields = "CommunityAddress.OBJECTID, CommunityAddress.Shape, CommunityAddress.SITEADDID, CommunityAddress.ADDRNUM, CommunityAddress.FULLNAME, CommunityAddress.FULLADDR, CommunityAddress.MUNICIPALITY, MunicipalBoundary.Name, MunicipalBoundary.MUNITYP, MunicipalBoundary.LOCALFIPS",
    };

    using (Geodatabase testVersion1Geodatabase = new Geodatabase(new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
    {
      AuthenticationMode = AuthenticationMode.DBMS,
      Instance = "instance",
      User = "user",
      Password = "password",
      Database = "database",
      Version = "user.testVersion1"
    }))
    {
      QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
      {
        Name = "CommunityAddrJounMunicipalBoundr",
        PrimaryKeys = testVersion1Geodatabase.GetSQLSyntax().QualifyColumnName("CommunityAddress", "OBJECTID")
      };

      // Will be based on testVersion1.
      using (Table queryTable = testVersion1Geodatabase.OpenQueryTable(queryTableDescription))
      {
        // Use queryTable.
      }
    }

    using (Geodatabase testVersion2Geodatabase = new Geodatabase(new DatabaseConnectionProperties(EnterpriseDatabaseType.Oracle)
    {
      AuthenticationMode = AuthenticationMode.DBMS,
      Instance = "instance",
      User = "user",
      Password = "password",
      Database = "database",
      Version = "user.testVersion2"
    }))
    {
      QueryTableDescription queryTableDescription = new QueryTableDescription(queryDef)
      {
        Name = "CommunityAddrJounMunicipalBoundr",
        PrimaryKeys = testVersion2Geodatabase.GetSQLSyntax().QualifyColumnName("CommunityAddress", "OBJECTID")
      };

      // Will be based on testVersion2.
      using (Table queryTable = testVersion2Geodatabase.OpenQueryTable(queryTableDescription))
      {
        // Use queryTable.
      }
    }
  });
}
Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3 or higher.
See Also