ArcObjects Library Reference (GeoDatabase)  

IRelationshipClass Interface

Provides access to members that return information about the relationship class, create relationships, relationship rules and get related objects. Note: the IRelationshipClass interface has been superseded byIRelationshipClass2. Please consider using the more recent version.

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

A RelationshipClass is an association between two object classes; one is the origin class and the other the destination class.  The RelationshipClass can have cardinality taking the form of 1-1, 1-M, M-N (One-to-One, One-to-Many, Many-to-Many).  A RelationshipClass may be simple or composite.  Composite relationship classes are 1-M where the origin class controls the lifetime of the destination class.  Simple relationship classes are peer-to-peer where the related objects can exist independent of each other.

When To Use

Use the RelationshipClass when you want to maintain particular associations between objects in a geodatabase.

Members

Description
Method AddRelationshipRule Adds a relationship rule to this relationship class.
Read-only property BackwardPathLabel The backward path label for the relationship class.
Read-only property Cardinality The cardinality for the relationship class.
Method CreateRelationship Creates a new relationship between the two specified objects.
Method DeleteRelationship Deletes the relationship that associates the two specified objects.
Method DeleteRelationshipRule Deletes a relationship rule from this relationship class.
Method DeleteRelationshipsForObject Deletes all relationships that apply to a specified object.
Method DeleteRelationshipsForObjectSet Deletes all relationships that apply to the specified origin or destination object set.
Read-only property DestinationClass The destination object class.
Read-only property DestinationForeignKey The relationship destination foreign Key.
Read-only property DestinationPrimaryKey The relationship destination primary Key.
Read-only property FeatureDataset The feature dataset, if any, to which this relationship class belongs.
Read-only property ForwardPathLabel The forward path label for the relationship class.
Method GetObjectsMatchingObjectSet Gets rows pairs of objects that are related to the specified origin or destination object set.
Method GetObjectsRelatedToObject Gets the objects that are related to the specified object.
Method GetObjectsRelatedToObjectSet Gets the objects that are related to the specified origin or destination object set.
Method GetRelationship Get the relationship that associates the two specified objects.
Method GetRelationshipsForObject Get all relationships that apply to a specified object.
Method GetRelationshipsForObjectSet Get all relationships that apply to the specified origin or destination object set.
Read-only property IsAttributed Indicates if the relationships in this relationship class have attributes.
Read-only property IsComposite Indicates if the relationship class represents a composite relationship in which the origin object class represents the composite object.
Read-only property Notification The notification direction for the relationship class.
Read-only property OriginClass The origin object class.
Read-only property OriginForeignKey The relationship origin foreign Key.
Read-only property OriginPrimaryKey The relationship origin primary Key.
Read-only property RelationshipClassID The relationship class ID.
Read-only property RelationshipRules The relationship rules that apply to this relationship class.

CoClasses that implement IRelationshipClass

CoClasses and Classes Description
AttributedRelationshipClass ESRI Attributed Relationship Class object.
MemoryRelationshipClass A relationship class object that is stored in memory.
RelationshipClass ESRI Relationship Class object.

Remarks

Relationships can be between spatial, non-spatial objects, or between spatial and non-spatial objects.  The spatial objects will be stored in feature classes, and the non-spatial in object classes, however, all of the relationships will be maintained in the relationship class.  RelationshipClasses can be created using the IRelationshipClassContainer interface on the FeatureDataset Class.

The IRelationshipClass interface provides information about a relationship class, functionality to create and delete individual relationships, and methods to find related objects. The members of this interface can be split into three logical groups: the properties that correspond to how the relationship class was created, the object-to-object methods that deal with individual relationships, and lastly the relationship rules methods.

The OriginPrimaryKey, OriginForeignKey, DestinationPrimaryKey, and DestinationForeignKey properties can be somewhat confusingtheir use is different depending on whether the relationship class is attributed.

The object-to-object methods such as GetObjectsRelatedToObjectSet make a lot of use of the ISet interface, which manipulates a set of generic objects. When adding objects to a set with a cursor, make sure that the cursor is non-recycling.

When using CreateRelationship, remember that this operation will write a value into the foreign key field. Therefore it is possible that you could overwrite, and therefore delete, an existing relationship. Similarly, DeleteRelationship will remove the foreign key value, so that field must allow null values unless you want to ensure that all objects in the class belong to relationships.

The IRelationshipClass::IsAttributed property will only return true if there are extra relationship attributes beyond those required to relate the objects. The IRelationshipClass::GetRelationship method is useful for accessing the relationship attributes.

[C#]

This C# example deletes all the relationships for features satisfying the where clause parameter.

public void DelRelationships(IRelationshipClass relationshipClass, IFeatureClass featureClass, string whereClause)
{
    // Get the features whose relationships you want to delete
    IQueryFilter queryFilter = new QueryFilterClass();
    queryFilter.WhereClause = whereClause;
    IFeatureCursor featureCursor = featureClass.Search(queryFilter, false);
    IFeature feature = null;
    ISet featureSet = new ESRI.ArcGIS.esriSystem.SetClass();
    while ((feature = featureCursor.NextFeature()) != null) {
      featureSet.Add(feature);
    }
    // Delete the relationships
    featureSet.Reset();
    Console.WriteLine("Count {0}", featureSet.Count);
    relationshipClass.DeleteRelationshipsForObjectSet(featureSet);
}

See Also

ISet Interface

.NET Related Topics

Creating class extensions | Creating relationship classes | Geodatabase | How to create a dynamic geocoded feature class | Joining data | Working with geodatabase rules |