ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Data Namespace / RelationshipClass Class / DeleteRelationship Method
The Row from the origin table.
The Row from the destination table.
Example

In This Topic
    DeleteRelationship Method
    In This Topic
    Removes a relationship between the two specified rows. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void DeleteRelationship( 
       Row originRow,
       Row destinationRow
    )
    Public Sub DeleteRelationship( _
       ByVal originRow As Row, _
       ByVal destinationRow As Row _
    ) 

    Parameters

    originRow
    The Row from the origin table.
    destinationRow
    The Row from the destination table.
    Exceptions
    ExceptionDescription
    originRow or destinationRow is null.
    This relationship class does not support this operation. For example, it is a virtual relationship class.
    A geodatabase-related exception has occurred.
    Remarks
    For relationships of type RelationshipCardinality.OneToOne or RelationshipCardinality.OneToMany deleting a relationship will write a null value to the destination row's origin foreign key field. For relationships of type RelationshipCardinality.ManyToMany, delete removes the relationship by removing the entry containing the origin foreign and destination foreign keys from the intermediate table.
    Example
    Deleting a Relationship
    public async Task DeletingARelationship()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file"))))
        using (RelationshipClass relationshipClass = geodatabase.OpenDataset<RelationshipClass>("LocalGovernment.GDB.luCodeViolationHasInspections"))
        using (FeatureClass violationsFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.luCodeViolation"))
        {
          QueryFilter queryFilter = new QueryFilter { WhereClause = "LOCDESC LIKE '%Jefferson%'" };
    
          using (RowCursor rowCursor = violationsFeatureClass.Search(queryFilter, false))
          {
            if (!rowCursor.MoveNext())
              return;
    
            using (Row jeffersonAveViolation = rowCursor.Current)
            {
              IReadOnlyList<Row> relatedDestinationRows = relationshipClass.GetRowsRelatedToOriginRows(new List<long> { jeffersonAveViolation.GetObjectID() });
    
              try
              {
                EditOperation editOperation = new EditOperation();
                editOperation.Callback(context =>
                {
                  foreach (Row relatedDestinationRow in relatedDestinationRows)
                  {
                    try
                    {
                      relationshipClass.DeleteRelationship(jeffersonAveViolation, relatedDestinationRow);
                    }
                    catch (GeodatabaseRelationshipClassException exception)
                    {
                      Console.WriteLine(exception);
                    }
                  }
                }, relationshipClass);
    
                bool editResult = editOperation.Execute();
              }
              finally
              {
                foreach (Row row in relatedDestinationRows)
                  row.Dispose();
              }
            }
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also