I have inherited a truly awful and very large ArcObjects project that was originally written in VB and then ported to C#. Apparently the source code I have been given is not the latest version and I am chasing down errors everywhere. The most challenging problem goes like this...
A number of tables are being joined (one after the other) to a Feature Layer via
IDisplayRelationshipClass.DisplayRelationshipClass. Let's call these tables A and B (there are more than 2). Each of these tables has fields 1 and 2. The ITable objects are created by using IFeatureWorkspace.OpenTable with a DBF file.
After the first join if I check the fields in my Feature Layer and at the end I can see A.1 and A.2 (field name prefixed with the name of the DBF file the table came from) - Great! However, after the second join A.1 and A.2 are gone, and in their place I have B.1, B.2 - not so great...
Do I need to do anything to persist the additional fields across these joins, so that I end up with A.1, A.2, B.1, B.2 etc. ? If I do, either this behaviour has changed since the code was first written, or the code never worked. Given that the fields are properly prefixed they shouldn't be overwriting each other.
The joins are happening like this:
IMemoryRelationshipClassFactory pMemRelFact = new MemoryRelationshipClassFactoryClass(); IRelationshipClass pRelClass = pMemRelFact.Open("TabletoLayer", (IObjectClass)pTTable, dbfJnField, (IObjectClass)pFeatLayer.FeatureClass, layerJnField, "forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany); IDisplayRelationshipClass pDispRC = (IDisplayRelationshipClass) pFeatLayer; pDispRC.DisplayRelationshipClass(pRelClass, esriJoinType.esriLeftInnerJoin);
Any assistance with this issue would be hugely appreciated.
EDIT: If this helps, I have observed something quite strange. After the join, pFeatLayer.FeatureClass.Fields.FieldsCount gives the original number of fields before the join, but ((ITable)pFeatLayer.Fields.FieldsCount gives the expected number (with joined fields). Unfortunately the pFeatLayer variable is then being passed back in to the join function, so it appears that tables are repeatedly being joined against the feature layer's initial state, hence only the last join making a difference.
Any suggestions for why an ITable cast would give a different field count to the FeatureClass? Is this a bug or just silly design??