Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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;

}
share|improve this question
    
I would enable SDE tracing and hit your SDE dataset again - hopefully the query that tries to collect the related data will fire and you can see what's failing. –  mwalker Aug 4 '10 at 15:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.