I have two workspaces - one a File GDB, the other SDE (SQL Server). Both workspaces contain the same data with the same relationship classes. When identifying features in ArcCatalog, the results pane correctly presents the related records.
When using IRelationshipclass.GetObjectsRelatedToObjectSet
, I always get an empty result set. If however I use a loop, calling IRelationshipclass.GetObjectsRelatedToObject
, I get the related records. I see the same result in both workspaces.
I have asked someone with a known good dataset to run my code, and they report that it works perfectly.
So my question is this - what in my workspace could cause this behavior? I need to rectify it.
For the record, I'm using ArcGIS 9.3 SP1. I've included my test code below, on the chance that there is an issue with my code.
public void test(IWorkspace workspace, IQueryFilter qf, string relClassName, string sourceTableName)
{
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IRelationshipClass relationshipClass = featureWorkspace.OpenRelationshipClass(relClassName);
ITable originTable = featureWorkspace.OpenTable(sourceTableName);
var sourceSet = originTable.Search(qf, false);
var foundSet = new SetClass();
IRow row;
while ((row = sourceSet.NextRow()) != null)
{
foundSet.Add(row);
}
var resultSet1 = GetRelatedRecordsByObject(relationshipClass, foundSet);
var resultSet2 = GetRelatedRecordsBySet(relationshipClass, foundSet);
System.Diagnostics.Debug.WriteLine("Result1: " + resultSet1.Count);
System.Diagnostics.Debug.WriteLine("Result2: " + resultSet2.Count);
}
public ISet GetRelatedRecordsBySet(IRelationshipClass relationship, ISet sourceObjectList)
{
sourceObjectList.Reset();
var resultSet = relationship.GetObjectsRelatedToObjectSet(sourceObjectList);
resultSet.Reset();
return resultSet;
}
public ISet GetRelatedRecordsByObject(IRelationshipClass relationship, ISet sourceObjectList)
{
ISet resultSet = new SetClass();
sourceObjectList.Reset();
IObject sourceRow;
while ((sourceRow = (IObject)sourceObjectList.Next()) != null)
{
var indSet = relationship.GetObjectsRelatedToObject(sourceRow);
indSet.Reset();
IRow indSetRow;
while ((indSetRow = (IRow)indSet.Next()) != null)
{
resultSet.Add(indSetRow);
}
}
resultSet.Reset();
return resultSet;
}