I have been struggling with this issue for hours now and am wondering if anyone else has encountered this.
I have a feature class (ADDRESS_MANAGER.GIS_INF_ADDRESS_P
) and a table (ADDRESS_MANAGER.GIS_TBL_ADDRESSCARD_B
).
Using ArcCatalog, I have verified the IDs of the feature class is 987 and the address card table is 981. I have verified the relationship exists from the feature class to the address card table (Relationship = ADDRESS_MANAGER.AddressCardHasAddress / Label = AddressCard / Origin=ADDRESS_MANAGER.GIS_INF_ADDRESS_P
).
However, no relationship classes are returned when I run this code:
var sourceId = sourceTable.GetID().ToString(); // returns "987"var destId = destTable.GetID().ToString(); // returns "981"IReadOnlyList<RelationshipClass> relationshipClasses = geodb.OpenRelationshipClass(sourceId, destId);
I have verified the geodb
object does indeed point to the geodatabase that holds both of these layers -- geodb is set directly from the feature class. Both layer IDs are correct, and there is definitely a relationship class between them. I am porting old ArcObject code over that did something similar, and I cannot figure out how to actually get this RelationshipClass anymore without hardcoding a reference to it.
This is ran in QueuedTask.Run
per the documentation. Additionally, when I try to use geodb.OpenDataset<RelationshipClass>
with any sort of relationship name (either the qualified full name, full name, or alias) I get a ArcGIS.Core.Data.GeodatabaseCatalogDatasetException: The item was not found
exception. It doesn't seem to matter if I set up geodb
by opening the appropriate SDE file, or if I set it from the feature class (the geodb is an enterprise geodabatase -- Oracle)
This is in ArcGIS Pro 2.2 - using C# / .NET 4.6.2
Solved! Go to Solution.
Thomas,
My apologies for not answering this earlier. I spent some time investigating this today. As currently implemented, the OpenRelationshipClass() method only works with feature service databases. We will review this implementation in a future release to see if we can extend it to cover additional database types. And we’ll definitely clarify the documentation as soon as possible.
To open a relationship class with an SDE or file geodatabase, you need to use the Geodatabase.OpenDataset<RelationshipClass> method, passing in the name of the relationship class. If you don’t know the name of the relationship class you can find it and open it up using code like the following:
IReadOnlyList<RelationshipClass> OpenRelationshipClass(Geodatabase geodatabase, string originClassName, string destinationClassName) { List<RelationshipClass> relationshipClasses = new List<RelationshipClass>(); IReadOnlyList<RelationshipClassDefinition> relationshipClassDefinitions = geodatabase.GetDefinitions<RelationshipClassDefinition>(); foreach (RelationshipClassDefinition relationshipClassDefinition in relationshipClassDefinitions) { if (relationshipClassDefinition.GetOriginClass() == originClassName && relationshipClassDefinition.GetDestinationClass() == destinationClassName) { relationshipClasses.Add(geodatabase.OpenDataset<RelationshipClass>(relationshipClassDefinition.GetName())); } relationshipClassDefinition.Dispose(); } return relationshipClasses; }
I hope this helps,
--Rich
Thomas,
My apologies for not answering this earlier. I spent some time investigating this today. As currently implemented, the OpenRelationshipClass() method only works with feature service databases. We will review this implementation in a future release to see if we can extend it to cover additional database types. And we’ll definitely clarify the documentation as soon as possible.
To open a relationship class with an SDE or file geodatabase, you need to use the Geodatabase.OpenDataset<RelationshipClass> method, passing in the name of the relationship class. If you don’t know the name of the relationship class you can find it and open it up using code like the following:
IReadOnlyList<RelationshipClass> OpenRelationshipClass(Geodatabase geodatabase, string originClassName, string destinationClassName) { List<RelationshipClass> relationshipClasses = new List<RelationshipClass>(); IReadOnlyList<RelationshipClassDefinition> relationshipClassDefinitions = geodatabase.GetDefinitions<RelationshipClassDefinition>(); foreach (RelationshipClassDefinition relationshipClassDefinition in relationshipClassDefinitions) { if (relationshipClassDefinition.GetOriginClass() == originClassName && relationshipClassDefinition.GetDestinationClass() == destinationClassName) { relationshipClasses.Add(geodatabase.OpenDataset<RelationshipClass>(relationshipClassDefinition.GetName())); } relationshipClassDefinition.Dispose(); } return relationshipClasses; }
I hope this helps,
--Rich
Thank you for the detailed response and corrective actions. The code snippet is very useful.
In the next release, Pro 2.3, anticipated in early 2019, we've changed Geodatabase.OpenRelationshipClass() so that it works with all geodatabase types, not just feature services.
--Rich
@RichRuh How do I retrieve the relationship class from a feature class? I have a feature class that has a relationship class. I won't know the name of the relationship class or the name of the destination table. Is there a way to retrieve the relationship class from a feature class that I am working with?