Create relationship class between two tables Pro sdk

575
2
Jump to solution
07-01-2021 11:30 AM
MarvisKisakye1
Occasional Contributor

Is there a way to create a relationship class between two TABLES with the pro sdk? Here is the code that I have used but the relationship class is not created in the geodatabase like I expect. @CharlesMacleod  @Wolf @UmaHarano 

var originFc = gdb.OpenDataset<FeatureClass>(mmember.Name);
                    var destFc = gdb.OpenDataset<FeatureClass>(etTableName);
                    var oidname = originFc.GetDefinition().GetObjectIDField();
                    var origPrimaryKey = originFc.GetDefinition().GetFields().First(f => string.Equals(oidname, f.Name));
                    var destForeignKey = destFc.GetDefinition().GetFields().First(f => string.Equals(ETTableSchema.rowIDFieldName, f.Name));
                    var rlDesc = new VirtualRelationshipClassDescription(origPrimaryKey, destForeignKey,
                        RelationshipCardinality.OneToMany);
                    rlDesc.ForwardPathLabel = "HasEdits";
                    rlDesc.BackwardPathLabel = "AllObjects";
                    rlDesc.Name = $"{mmember.Name}_HTE";
                    var rlClass = originFc.RelateTo(destFc, rlDesc);

 

0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

We started to add some data definition language (DDL) capabilities in the Pro SDK at 2.8, but you cannot yet create relationship classes (it's planned for a future release).  For now, you have to use the geoprocessing API and use the Create Relationship Class tool.

--Rich

 

View solution in original post

2 Replies
RichRuh
Esri Regular Contributor

We started to add some data definition language (DDL) capabilities in the Pro SDK at 2.8, but you cannot yet create relationship classes (it's planned for a future release).  For now, you have to use the geoprocessing API and use the Create Relationship Class tool.

--Rich

 

Wolf
by Esri Regular Contributor
Esri Regular Contributor

@MarvisKisakye1 You probably already looked at this sample:  arcgis-pro-sdk-community-samples/Geodatabase/DynamicJoins at master · Esri/arcgis-pro-sdk-community-...

However, the sample only creates a 'dynamic' result (added to the TOC).  To create a relationship class in the geodatabase you have to follow Rich's suggestion.