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