ArcGIS Pro 3.6 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 string GetObjectIDField()
    Public Function GetObjectIDField() As String

    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
    public async Task ObtainingDefinitionsFromFS(string url)
    {
        //Url examples for (federated) feature services
        //(by "ref" online):
        //https://sampleserver6.arcgisonline.com/arcgis/rest/services/LocalGovernment/Recreation/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, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also