Joining Table to Feature

Discussion created by ccposton on Mar 28, 2012
Latest reply on Apr 3, 2012 by ccposton
I use the following code to do a join but when this routine has completed without error my featureLayer still has a FeatureClass that looks the same as before I run this code. What does the DisplayRelationshipClass() call actually do? I see the help talking about creating an IRelQueryTable under the covers but if this code is not going to update the information that my featureLayer returns then it is not really joining anything. How can I get an actual join?

private void JoinTableToFeature( IFeatureLayer featureLayer, ITable externalTable ) {

    IGeoFeatureLayer geoFeatureLayer = featureLayer as IGeoFeatureLayer;
    IMemoryRelationshipClassFactory memoryRelationshipFactory = null;

    try {
        Type memoryRelationshipClassFactory = Type.GetTypeFromProgID( "esriGeodatabase.MemoryRelationshipClassFactory" );
        memoryRelationshipFactory = Activator.CreateInstance( memoryRelationshipClassFactory )
            as IMemoryRelationshipClassFactory;

        IRelationshipClass relationshipClass =
                externalTable as IObjectClass,
                geoFeatureLayer.DisplayFeatureClass as IObjectClass,
                esriRelCardinality.esriRelCardinalityOneToOne );

        IDisplayRelationshipClass displayRelationshipClass = featureLayer as IDisplayRelationshipClass;
        displayRelationshipClass.DisplayRelationshipClass( relationshipClass, esriJoinType.esriLeftOuterJoin );
    finally {

        Marshal.FinalReleaseComObject( memoryRelationshipFactory );