Provides access to members that return information about the relationship class, create relationships, relationship rules and get related objects.
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
Name | 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. |
IRelationshipClass.AddRelationshipRule Method
Adds a relationship rule to this relationship class.
Public Sub AddRelationshipRule ( _
ByVal Rule As IRule _
)
public void AddRelationshipRule (
IRule Rule
);
Remarks
The AddRelationshipRulemethod 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:
IRelationshipClass.BackwardPathLabel Property
The backward path label for the relationship class.
Public ReadOnly Property BackwardPathLabel As String
public string BackwardPathLabel {get;}
Remarks
The BackwardPathLabelproperty returns the path label for the backward direction path. An example can be shown by using a relationship between a pump station and its pumps. A backward path label may be something like "Contained by". It would be read as a pump is 'Contained by' the pump station.
IRelationshipClass.Cardinality Property
The cardinality for the relationship class.
Public ReadOnly Property Cardinality As esriRelCardinality
public esriRelCardinality Cardinality {get;}
Remarks
The Cardinalityproperty returns the cardinality of the relationship class as an esriRelCardinality enumeration value. It refers to the type of relationship formed between an origin class and a destination class. It can be one of three types: esriRelCardinalityOneToOne (1-1), esriRelCardinalityOneToMany (1-M), or esriRelCardinalityManyToMany (M-N).
IRelationshipClass.CreateRelationship Method
Creates a new relationship between the two specified objects.
Public Function CreateRelationship ( _
ByVal OriginObject As IObject, _
ByVal DestinationObject As IObject _
) As IRelationship
public IRelationship CreateRelationship (
IObject OriginObject,
IObject DestinationObject
);
Remarks
The CreateRelationshipmethod creates a relationship between the origin object and the destination object specified in the parameters. By default, when a relationship class is created, a relationship is created between the objects with corresponding primary and foreign key values. When subsequently using CreateRelationship, remember that this operation will write a value into the foreign key field. Therefore, in the case of 1:1 and 1:M relationship classes, it is possible that you could overwrite, and therefore delete, an existing relationship.
This method should be called within an edit session.
IRelationshipClass.DeleteRelationship Method
Deletes the relationship that associates the two specified objects.
Public Sub DeleteRelationship ( _
ByVal OriginObject As IObject, _
ByVal DestinationObject As IObject _
)
public void DeleteRelationship (
IObject OriginObject,
IObject DestinationObject
);
Remarks
The DeleteRelationshipmethod deletes the relationship between the origin object and destination object specified in the parameters. This will remove the entry for this relationship from the relationship class.
This method should be called within an edit session.
IRelationshipClass.DeleteRelationshipRule Method
Deletes a relationship rule from this relationship class.
Public Sub DeleteRelationshipRule ( _
ByVal Rule As IRule _
)
public void DeleteRelationshipRule (
IRule Rule
);
Remarks
The DeleteRelationshipRulemethod deletes a relationship rule from 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.
IRelationshipClass.DeleteRelationshipsForObject Method
Deletes all relationships that apply to a specified object.
Public Sub DeleteRelationshipsForObject ( _
ByVal anObject As IObject _
)
public void DeleteRelationshipsForObject (
IObject anObject
);
Remarks
The DeleteRelationshipsForObjectmethod is used for removing all of the relationships in the relationship class that the specified object belongs to. Note that this method is bi-directional; the specified object could belong to the origin class or destination class.
This method should be called within an edit session.
IRelationshipClass.DeleteRelationshipsForObjectSet Method
Deletes all relationships that apply to the specified origin or destination object set.
Public Sub DeleteRelationshipsForObjectSet ( _
ByVal anObjectSet As ISet _
)
public void DeleteRelationshipsForObjectSet (
ISet anObjectSet
);
Remarks
The DeleteRelationshipsForObjectSetmethod is used for removing all relationships in a particular relationship class for the specified set of objects.
This method works in the same way as the DeleteRelationshipsForObjectmethod, except on a set of objects rather than a single one. If a cursor is used to populate the set with objects, ensure that a non-recycling cursor is used.
This method should be called within an edit session.
//e.g., nameOfRelClass = "relclass"
// nameOfOriginTable = "origintable"
public void IRelationshipClass__DeleteRelationshipsForObjectSet(IWorkspace workspace, string nameOfRelClass, string nameOfOriginTable)
{
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IRelationshipClass relationshipClass = featureWorkspace.OpenRelationshipClass(nameOfRelClass);
ITable originTable = featureWorkspace.OpenTable(nameOfOriginTable);
ESRI.ArcGIS.esriSystem.ISet objectSet = new ESRI.ArcGIS.esriSystem.SetClass();
objectSet.Add(originTable.GetRow(1));
objectSet.Add(originTable.GetRow(2));
objectSet.Add(originTable.GetRow(3));
objectSet.Reset();
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
relationshipClass.DeleteRelationshipsForObjectSet(objectSet);
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
objectSet = null;
}
IRelationshipClass.DestinationClass Property
The destination object class.
Public ReadOnly Property DestinationClass As IObjectClass
public IObjectClass DestinationClass {get;}
IRelationshipClass.DestinationForeignKey Property
The relationship destination foreign Key.
Public ReadOnly Property DestinationForeignKey As String
public string DestinationForeignKey {get;}
Remarks
The DestinationForeignKeyproperty returns the name of the destination foreign key field. This property is null except in the case of attributed relationship classes, in which case it is the name of a field in the relationship table. The values in this field reference values in the field designated as the destination primary key.
IRelationshipClass.DestinationPrimaryKey Property
The relationship destination primary Key.
Public ReadOnly Property DestinationPrimaryKey As String
public string DestinationPrimaryKey {get;}
IRelationshipClass.FeatureDataset Property
The feature dataset, if any, to which this relationship class belongs.
Public ReadOnly Property FeatureDataset As IFeatureDataset
public IFeatureDataset FeatureDataset {get;}
Remarks
The FeatureDatasetproperty returns the feature dataset that this relationship class belongs to. If the relationship class exists outside of a feature dataset, a null value will be returned.
IRelationshipClass.ForwardPathLabel Property
The forward path label for the relationship class.
Public ReadOnly Property ForwardPathLabel As String
public string ForwardPathLabel {get;}
Remarks
The ForwardPathLabelproperty returns the path label for the forward direction path. An example can be shown by using a relationship between a pump station and its pumps. A forward path label may be something like "Contains". It would be read as a pump station 'Contains' pumps.
IRelationshipClass.GetObjectsMatchingObjectSet Method
Gets rows pairs of objects that are related to the specified origin or destination object set.
Public Function GetObjectsMatchingObjectSet ( _
ByVal srcObjectSet As ISet _
) As IRelClassEnumRowPairs
public IRelClassEnumRowPairs GetObjectsMatchingObjectSet (
ISet srcObjectSet
);
Remarks
The GetObjectsMatchingObjectSetmethod returns an enumerator of related object pairs based on the object set provided as a parameter. The enumerator contains a related object pair for each relationship participated in by the input objects. For example, in a relationship class with 1:1 cardinality, passing three objects into this method will return three related object pairs, assuming all three objects participate in a relationship. In a relationship class with 1:M or M:N cardinality, passing in a single object could conceivably result in an enumerator with multiple related object pairs, if the object participates in several relationships.
If the input set is constructed with a cursor, ensure that a non-recycling cursor is used.
IRelationshipClass.GetObjectsRelatedToObject Method
Gets the objects that are related to the specified object.
Public Function GetObjectsRelatedToObject ( _
ByVal anObject As IObject _
) As ISet
public ISet GetObjectsRelatedToObject (
IObject anObject
);
Remarks
TheGetObjectsRelatedToObjectmethod returns a set of Objects (or subtypes of Object, such as features) that are related to the anObject object.
IRelationshipClass.GetObjectsRelatedToObjectSet Method
Gets the objects that are related to the specified origin or destination object set.
Public Function GetObjectsRelatedToObjectSet ( _
ByVal anObjectSet As ISet _
) As ISet
public ISet GetObjectsRelatedToObjectSet (
ISet anObjectSet
);
Remarks
The GetObjectsRelatedToObjectSet method returns a set of objects that are related to the objects contained by the _anObjectSet_parameter. It behaves the same as GetObjectsRelatedToObject, except that it accepts a set of objects as a parameter.
If multiple objects in the input set are related to a common object, that object will only be included once in the returned set.
If the input set is constructed with a cursor, ensure that a non-recycling cursor is used.
//e.g., nameOfRelClass = "relclass"
// nameOfOriginTable = "origintable"
public void IRelationshipClass__GetObjectsRelatedToObjectSet(IWorkspace workspace, string nameOfRelClass, string nameOfOriginTable)
{
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IRelationshipClass relationshipClass = featureWorkspace.OpenRelationshipClass(nameOfRelClass);
ITable originTable = featureWorkspace.OpenTable(nameOfOriginTable);
ESRI.ArcGIS.esriSystem.ISet objectSet = new ESRI.ArcGIS.esriSystem.SetClass();
objectSet.Add(originTable.GetRow(1));
objectSet.Add(originTable.GetRow(2));
objectSet.Add(originTable.GetRow(3));
objectSet.Reset();
ESRI.ArcGIS.esriSystem.ISet resultSet = relationshipClass.GetObjectsRelatedToObjectSet(objectSet);
objectSet = null;
}
IRelationshipClass.GetRelationship Method
Get the relationship that associates the two specified objects.
Public Function GetRelationship ( _
ByVal OriginObject As IObject, _
ByVal DestinationObject As IObject _
) As IRelationship
public IRelationship GetRelationship (
IObject OriginObject,
IObject DestinationObject
);
Remarks
When using a relationship class, the GetRelationshipmethod is used for returning a relationship interface to the relationship between the origin object and destination object specified in the function parameters. This can be used to retrieve the relationship between two objects.
IRelationshipClass.GetRelationshipsForObject Method
Get all relationships that apply to a specified object.
Public Function GetRelationshipsForObject ( _
ByVal anObject As IObject _
) As IEnumRelationship
public IEnumRelationship GetRelationshipsForObject (
IObject anObject
);
Remarks
The GetRelationshipsForObjectmethod returns an IEnumRelationship enumerator containing the relationships that the _anObject_parameter participates in.
IRelationshipClass.GetRelationshipsForObjectSet Method
Get all relationships that apply to the specified origin or destination object set.
Public Function GetRelationshipsForObjectSet ( _
ByVal anObjectSet As ISet _
) As IEnumRelationship
public IEnumRelationship GetRelationshipsForObjectSet (
ISet anObjectSet
);
Remarks
The GetRelationshipsForObjectSetmethod returns an IEnumRelationship enumerator containing the relationships that the objects in _anObjectSet_parameter participate in.
If the input set is constructed with a cursor, ensure that a non-recycling cursor is used.
IRelationshipClass.IsAttributed Property
Indicates if the relationships in this relationship class have attributes.
Public ReadOnly Property IsAttributed As Boolean
public bool IsAttributed {get;}
Remarks
The IsAttributedproperty indicates whether this relationship class is attributed or not. An attributed relationship class has extra attributes that are being maintained for each relationship. For example, in a relationship class between parcels and owners, percentage of ownership each particular owner has could be stored as a relationship attribute.
The IsAttributedproperty will only return true if there are extra relationship attributes beyond those required to relate the objects. In the case of relationship classes with M:N cardinality, there will be a relationship table (see 'AttributedRelationshipClass' in the object model diagram), but IsAttributedwill return False, unless there are additional attributes.
IRelationshipClass.IsComposite Property
Indicates if the relationship class represents a composite relationship in which the origin object class represents the composite object.
Public ReadOnly Property IsComposite As Boolean
public bool IsComposite {get;}
Remarks
The IsCompositeproperty indicates whether this relationship class is composite or simple. A composite relationship class is one where objects in the origin class control the lifetime of the objects in the destination class. When the origin object is deleted, the related destination object is also deleted. Composite relationship classes are always one to many relationships, but this can be constrained to one to one through the use of relationship rules.
If a relationship class is not composite, it is considered 'simple', and related objects are independent of each other. Simple relationships can be of any cardinality.
IRelationshipClass.Notification Property
The notification direction for the relationship class.
Public ReadOnly Property Notification As esriRelNotification
public esriRelNotification Notification {get;}
Remarks
The Notificationproperty returns the relationship class' notification behavior as as esriRelNotification enumeration value. A notification occurs when an event happens, such as a deletion or an edit. It can be one of four type: esriRelNotificationNone, esriRelNotificationForward, esriRelNotificationBackward, or esriRelNotificationBoth. None means no notification will take place, forward means that notification will happen from the origin to the destination, backward means notification occurs from the destination to the origin, and both means notification will happen both ways when an event occurs.
IRelationshipClass.OriginClass Property
The origin object class.
Public ReadOnly Property OriginClass As IObjectClass
public IObjectClass OriginClass {get;}
Remarks
When using a relationship class, the OriginClassproperty is used for returning an interface to the origin objectclass .
IRelationshipClass.OriginForeignKey Property
The relationship origin foreign Key.
Public ReadOnly Property OriginForeignKey As String
public string OriginForeignKey {get;}
IRelationshipClass.OriginPrimaryKey Property
The relationship origin primary Key.
Public ReadOnly Property OriginPrimaryKey As String
public string OriginPrimaryKey {get;}
IRelationshipClass.RelationshipClassID Property
The relationship class ID.
Public ReadOnly Property RelationshipClassID As Integer
public int RelationshipClassID {get;}
Remarks
The RelationshipClassIDproperty returns the ID of the relationship class. This ID uniquely identifies a relationship class within its geodatabase relative to other relationship classes. It is equivalent to IObjectClass::ObjectClassID except that it applies to relationship classes rather than object classes.
IRelationshipClass.RelationshipRules Property
The relationship rules that apply to this relationship class.
Public ReadOnly Property RelationshipRules As IEnumRule
public IEnumRule RelationshipRules {get;}
Remarks
The RelationshipRulesproperty retrieves the relationship rules of the relationship class as an IEnumRule enumerator. 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.
Classes that implement IRelationshipClass
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 IRelationshipClassContainerinterface on the FeatureDataset Class.
The IRelationshipClassinterface 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 DestinationForeignKeyproperties can be somewhat confusing�their use is different depending on whether the relationship class is attributed.
The object-to-object methods such as GetObjectsRelatedToObjectSetmake a lot of use of the ISetinterface, 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, DeleteRelationshipwill 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::IsAttributedproperty will only return true if there are extra relationship attributes beyond those required to relate the objects. The IRelationshipClass::GetRelationshipmethod is useful for accessing the relationship attributes.
This C# example deletes all the relationships for features satisfying the where clause parameter.