Select to view content in your preferred language

ArcGIS Pro SDK OpenRelationshipClass does not return results

1405
4
Jump to solution
08-27-2018 01:45 PM
ThomasHorner
New Contributor

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

0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

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

View solution in original post

4 Replies
RichRuh
Esri Regular Contributor

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

ThomasHorner
New Contributor

Thank you for the detailed response and corrective actions.  The code snippet is very useful.

RichRuh
Esri Regular Contributor

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

0 Kudos
MarvisKisakye1
Regular Contributor

@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?

0 Kudos