ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / TableDefinition Class / GetObjectIDField Method
Example

In This Topic
    GetObjectIDField Method (TableDefinition)
    In This Topic
    Gets the name of the ObjectID field. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function GetObjectIDField() As String
    public string GetObjectIDField()

    Return Value

    The name of the ObjectID field.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    Example
    Obtaining Definitions from a Feature Service by Layer ID
    {
      //Url examples for (federated) feature services
      //(by "ref" online):
      var url =
          @"https://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer";
      //(federated by ref on portal)
      //https://portal.example.com/server/rest/services/FeatureServiceName/FeatureServer");
      //(federated by value - Hosted - on portal)
      //https://portal.example.com/server/rest/services/Hosted/FeatureServiceName/FeatureServer");
    
      await QueuedTask.Run(() =>
      {
        var uri = new Uri(url, UriKind.Absolute);
        using (var fs_db = new ArcGIS.Core.Data.Geodatabase(new ServiceConnectionProperties(uri)))
        {
          //Assuming that id 0 is a FeatureClass for the given service
          FeatureClassDefinition featureClassDefinition =
              fs_db.GetDefinition<FeatureClassDefinition>("0");
          string shapeField = featureClassDefinition.GetShapeField();
          IReadOnlyList<Field> fields = featureClassDefinition.GetFields();
    
          //Assuming that id 1 is a Table for the given service
          TableDefinition tableDefinition =
                fs_db.GetDefinition<TableDefinition>("1");
          string objectIDField = tableDefinition.GetObjectIDField();
        }
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also