ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Data Namespace / Geodatabase Class / Evaluate Method
Represents a query involving one or more tables from the same geodatabase.
If set to true, all the entries in RowCursor will reference the most current row returned by RowCursor.Current. To ensure all the entries in RowCursor remain unique, set useRecyclingCursor to false.
Example

In This Topic
    Evaluate Method (Geodatabase)
    In This Topic
    Evaluates the query and return a RowCursor.
    Syntax
    Public Function Evaluate( _
       ByVal queryDef As QueryDef, _
       Optional ByVal useRecyclingCursor As Boolean _
    ) As RowCursor

    Parameters

    queryDef
    Represents a query involving one or more tables from the same geodatabase.
    useRecyclingCursor
    If set to true, all the entries in RowCursor will reference the most current row returned by RowCursor.Current. To ensure all the entries in RowCursor remain unique, set useRecyclingCursor to false.

    Return Value

    A RowCursor that encapsulates the retrieved rows of type Row or Feature.
    Exceptions
    ExceptionDescription
    No valid geodatabase has been opened prior to invoking this operation.
    queryDef is null.
    A geodatabase-related exception has occurred.
    Remarks
    The rows retrieved from the RowCursor may be of type Row or Feature. If there exists a feature class (i.e., spatial table) specified in the QueryDef.Tables's comma-delimited string AND the QueryDef.SubFields contains either the default value (i.e., "*") or the spatial field name (e.g., "SHAPE" of type FieldType.Geometry), then the retrieved rows are of type Feature. Otherwise, they are of type Row.
    Example
    Evaluating a QueryDef on a single table
    public async Task SimpleQueryDef()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
        {
          QueryDef adaCompilantParksQueryDef = new QueryDef
          {
            Tables = "Park",
            WhereClause = "ADACOMPLY = 'Yes'",
          };
    
          using (RowCursor rowCursor = geodatabase.Evaluate(adaCompilantParksQueryDef, false))
          {
            while (rowCursor.MoveNext())
            {
              using (Row row = rowCursor.Current)
              {
                Feature feature = row as Feature;
                Geometry shape = feature.GetShape();
    
                String type = Convert.ToString(row["ADACOMPLY"]); // will be "Yes" for each row.
    
                try
                {
                  Table table = row.GetTable(); // Will always throw exception.
                }
                catch (NotSupportedException exception)
                {
                  // Handle not supported exception.
                }
              }
            }
          }
        }
      });
    }
    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
              }
            }
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also