ArcObjects Library Reference (GeoDatabase)  

IRelationshipClass.AddRelationshipRule Method

Adds a relationship rule to this relationship class.

[Visual Basic .NET]
Public Sub AddRelationshipRule ( _
    ByVal Rule As IRule _
)
[C#]
public void AddRelationshipRule (
    IRule Rule
);
[C++]
HRESULT AddRelationshipRule(
  IRule* Rule
);
[C++]

Parameters

Rule [in]

  Rule is a parameter of type IRule

Product Availability

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

Remarks

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.

[C#]

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;
relationshipClass.AddRelationshipRule(relationshipRule);

See Also

IRelationshipClass Interface

.NET Related Topics

Working with geodatabase rules |