Return Value
The name of the origin (primary) key field.
Exception | Description |
---|---|
ArcGIS.Core.Data.Exceptions.GeodatabaseException | A geodatabase-related exception has occurred. |
public async Task CreatingARelationship() { await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file")))) using (RelationshipClass relationshipClass = geodatabase.OpenDataset<RelationshipClass>("LocalGovernment.GDB.OverviewToProject")) using (FeatureClass projectsFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.CIPProjects")) using (FeatureClass overviewFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.CIPProjectsOverview")) { // This will be PROJNAME. This can be used to get the field index or used directly as the field name. string originKeyField = relationshipClass.GetDefinition().GetOriginKeyField(); EditOperation editOperation = new EditOperation(); editOperation.Callback(context => { // The rows are being added to illustrate adding relationships. If one has existing rows, those can be used to add a relationship. using (RowBuffer projectsRowBuffer = projectsFeatureClass.CreateRowBuffer()) using (RowBuffer overviewRowBuffer = overviewFeatureClass.CreateRowBuffer()) { projectsRowBuffer["TOTCOST"] = 500000; overviewRowBuffer[originKeyField] = "LibraryConstruction"; overviewRowBuffer["PROJECTMAN"] = "John Doe"; overviewRowBuffer["FUNDSOUR"] = "Public"; using (Row projectsRow = projectsFeatureClass.CreateRow(projectsRowBuffer)) using (Row overviewRow = overviewFeatureClass.CreateRow(overviewRowBuffer)) { Relationship relationship = relationshipClass.CreateRelationship(overviewRow, projectsRow); //To Indicate that the Map has to draw this feature/row and/or the attribute table has to be updated context.Invalidate(projectsRow); context.Invalidate(overviewRow); context.Invalidate(relationshipClass); } } }, projectsFeatureClass, overviewFeatureClass); bool editResult = editOperation.Execute(); } }); }
Target Platforms: Windows 11, Windows 10, Windows 8.1