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();
}