GetRowsRelatedToOriginRows Method
Gets the rows from the destination table that are related to the origin row object IDs.
This method must be called on the MCT. Use QueuedTask.Run.
Parameters
- originObjectIDs
-
The ObjectIDs from the origin tables rows.
Return Value
A list with the related destination tables
Rows. If is an empty list or none of its content (i.e., OIDs) matches any row in the relationship class, an empty list will be returned.
Getting Rows related by RelationshipClass
public async Task GettingRowsRelatedByRelationshipClass()
{
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.luCodeViolationHasInspections"))
using (FeatureClass violationsFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.luCodeViolation"))
using (Table inspectionTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.luCodeInspection"))
{
List<Row> jeffersonAveViolations = new List<Row>();
QueryFilter queryFilter = new QueryFilter { WhereClause = "LOCDESC LIKE '%Jefferson%'" };
using (RowCursor rowCursor = violationsFeatureClass.Search(queryFilter, false))
{
while (rowCursor.MoveNext())
{
jeffersonAveViolations.Add(rowCursor.Current);
}
}
IReadOnlyList<Row> relatedOriginRows = null;
IReadOnlyList<Row> relatedDestinationRows = null;
try
{
QueryFilter filter = new QueryFilter { WhereClause = "ACTION = '1st Notice'" };
using (Selection selection = inspectionTable.Select(filter, SelectionType.ObjectID, SelectionOption.Normal))
{
relatedOriginRows = relationshipClass.GetRowsRelatedToDestinationRows(selection.GetObjectIDs());
}
bool containsJeffersonAve = relatedOriginRows.Any(row => Convert.ToString(row["LOCDESC"]).Contains("Jefferson"));
List<long> jeffersonAveViolationObjectIds = jeffersonAveViolations.Select(row => row.GetObjectID()).ToList();
relatedDestinationRows = relationshipClass.GetRowsRelatedToOriginRows(jeffersonAveViolationObjectIds);
bool hasFirstNoticeInspections = relatedDestinationRows.Any(row => Convert.ToString(row["ACTION"]).Contains("1st Notice"));
}
finally
{
Dispose(jeffersonAveViolations);
Dispose(relatedOriginRows);
Dispose(relatedDestinationRows);
}
}
});
}
private static void Dispose(IEnumerable<Row> rows)
{
foreach (Row row in rows)
row.Dispose();
}
Deleting a Relationship
public async Task DeletingARelationship()
{
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.luCodeViolationHasInspections"))
using (FeatureClass violationsFeatureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.luCodeViolation"))
{
QueryFilter queryFilter = new QueryFilter { WhereClause = "LOCDESC LIKE '%Jefferson%'" };
using (RowCursor rowCursor = violationsFeatureClass.Search(queryFilter, false))
{
if (!rowCursor.MoveNext())
return;
using (Row jeffersonAveViolation = rowCursor.Current)
{
IReadOnlyList<Row> relatedDestinationRows = relationshipClass.GetRowsRelatedToOriginRows(new List<long> { jeffersonAveViolation.GetObjectID() });
try
{
EditOperation editOperation = new EditOperation();
editOperation.Callback(context =>
{
foreach (Row relatedDestinationRow in relatedDestinationRows)
{
try
{
relationshipClass.DeleteRelationship(jeffersonAveViolation, relatedDestinationRow);
}
catch (GeodatabaseRelationshipClassException exception)
{
Console.WriteLine(exception);
}
}
}, relationshipClass);
bool editResult = editOperation.Execute();
}
finally
{
foreach (Row row in relatedDestinationRows)
row.Dispose();
}
}
}
}
});
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.