This document is archived and information here might be outdated.  Recommended version.

IRelationshipClass.AddRelationshipRule Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Geodatabase > ESRI.ArcGIS.GeoDatabase > Interfaces > IR > IRelationshipClass Interface > IRelationshipClass.AddRelationshipRule Method
ArcGIS Developer Help

IRelationshipClass.AddRelationshipRule Method

Adds a relationship rule to this relationship class.

[Visual Basic .NET]
Public Sub AddRelationshipRule ( _
    ByVal Rule As IRule _
public void AddRelationshipRule (
    IRule Rule
HRESULT AddRelationshipRule(
  IRule* Rule
Rule [in]

Rule is a parameter of type IRule*

Product Availability

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


The AddRelationshipRule method adds a new relationship rule to the relationship class. Relationship classes can have an associated set of relationship rules. These rules are used to control which object subtypes from the origin class can be related to which object subtypes in the destination class. They can also be used to specify a valid cardinality range for all permissable subtype pairs. For example, in a feature class containing utility poles divided into wooden and steel subtypes, relationship rules could be used to specify that wooden poles may have one to three transformers attached, but steel poles may have one to five transformers attached.


Below is a small C# code sample of how to add a relationship rule:

IFeatureClass originFeatureClass = featureWorkspace.OpenFeatureClass("us_counties");
IFeatureClass destFeatureClass = featureWorkspace.OpenFeatureClass("poles");
IRelationshipClass relationshipClass = featureWorkspace.OpenRelationshipClass("transformers");
IRelationshipRule relationshipRule = (IRelationshipRule) new RelationshipRuleClass();
relationshipRule.DestinationClassID = destFeatureClass.ObjectClassID;
relationshipRule.DestinationSubtypeCode = 0;    
relationshipRule.DestinationMaximumCardinality = 1;
relationshipRule.DestinationMinimumCardinality = 5;
relationshipRule.OriginClassID = originFeatureClass.ObjectClassID;
relationshipRule.OriginSubtypeCode = 0;
relationshipRule.OriginMaximumCardinality = 1;
relationshipRule.OriginMinimumCardinality = 1;

See Also

IRelationshipClass Interface