imkamp

Join ignores the DefinitionExpression

Discussion created by imkamp on Feb 18, 2013
Latest reply on Mar 4, 2013 by imkamp
I wrote the following code to get a FeatureClass with legend information corresponding to the map sheet (for example "TK=1234").
But the result of the join doesn't care of the DefinitionExpression.
When I do the same in ArcMap the result is how I expected. But programmatically

// 1. add a FeatureLayer from a FileGeoDatabase
IFeatureClass fcGeol = MyTools.LoadFeatureClass("FileGDB", sPath, "Geologische_Karten.gdb", sLayername);
IFeatureLayer2 flyrGeol = new FeatureLayerClass();
flyrGeol.FeatureClass = fcGeol;
ILayer lyrGeol = (ILayer)flyrGeol;
lyrGeol.Name = sLayername;
currentMap.AddLayer(lyrGeol);

// 2. add Table "Legenden" from "\Schichtenkatalog.mdb"ITable tabLegenden = MyTools.LoadTable("Access", sPath + "\\GeolLayers.mdb", "Legenden");

IStandaloneTable staloneTabLegenden = new StandaloneTableClass();
staloneTabLegenden.Table = tabLegenden;
staloneTabLegenden.Name = "Legenden";

// 3. set the DefinitionQuery !!!ITableDefinition tabdefLegenden = staloneTabLegenden as ITableDefinition;
tabdefLegenden.DefinitionExpression = "Legenden.TK = 1234";

// 4. add the Table "Legenden" to the StandaloneTableCollectionIStandaloneTableCollection standaloneTabColl = currentMap as IStandaloneTableCollection;
standaloneTabColl.AddStandaloneTable(staloneTabLegenden);

// 5. join the Table "Legenden" to the FeatureClassIDisplayRelationshipClass dispRelClass = flyrGeol as IDisplayRelationshipClass;
// create an InMemory-RelationshipClass-Objekt
Type t = Type.GetTypeFromProgID("esriGeodatabase.MemoryRelationshipClassFactory");
memrelFactory = Activator.CreateInstance(t) as IMemoryRelationshipClassFactory;
IRelationshipClass relationshipClass = memrelFactory.Open("Relation1",
(IObjectClass)fcGeol, "KOMBINR", (IObjectClass)staloneTabLegenden.Table, "KOMBINR",
"forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany);
dispRelClass.DisplayRelationshipClass(relationshipClass, esriJoinType.esriLeftOuterJoin);

// 5(b). attempt with DisplayTableIDisplayTable pDisplayTableLegend = staloneTabLegenden as IDisplayTable;
IRelationshipClass relationshipClass = memrelFactory.Open("Relation1",
(IObjectClass)fcGeol, "KOMBINR", (IObjectClass)pDisplayTableLegend.DisplayTable, "KOMBINR",
"forward", "backward", esriRelCardinality.esriRelCardinalityOneToMany);
dispRelClass.DisplayRelationshipClass(relationshipClass, esriJoinType.esriLeftOuterJoin);

How can I get the join to notice my DefinitionExpression?

Thanks for your replies in advance.
Ines

Outcomes