How to query all rows from a joined table?

688
5
08-13-2020 09:29 AM
GEOINT_ENGINEER
Esri Contributor

We tried to query all rows from a feature layer having a joined table and obtain all row values. When we are using the IDisplayTable::GetFieldDescription method all fields (also the joined fields) are returned, but when we are iterating through the RowCursor returned by IDisplayTable::Search only the values of the "origin table" are returned any access using a field index targetting a field from the joined table by Row::GetValue(fieldIndex) leads to a null reference.

Is this a known issue or do we need to downcast from FeatureLayer/StandaloneTable, or just access the row values using a different approach?

Thanks in advance. 

0 Kudos
5 Replies
GEOINT_ENGINEER
Esri Contributor

Any ArcGIS Pro SDK Join expert out there? Rich Ruh‌ 

0 Kudos
RichRuh
Esri Regular Contributor

Hi Jan,

I'm not that familiar with the layer-level query routines that you're using.  Have you tried just calling FeatureLayer.GetFeatureClass() and querying against that?

--Rich

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Hi Jan,

 I just tried this using release 2.6 and it is working for me.  In my test I have a feature layer that is joined to a table (both the feature layer and the table are in the TOC).  I retrieve the feature layer for the query from the map using:

var featureLayer = MapView.Active.Map.Layers.OfType<FeatureLayer>().Where (l => l.Name.Equals (...));

In my sample I only query the selected features, however, I see all values including the values of the joined table:

QueryFilter qf = new QueryFilter()
{
    ObjectIDs = featureLayer.GetSelection().GetObjectIDs()
};
using (var rowCursor = featureLayer.Search(qf))
{
    while (rowCursor.MoveNext())
    {
        using (var anyRow = rowCursor.Current)
        {
            foreach (var fld in anyRow.GetFields().Where(fld => fld.FieldType != FieldType.Geometry))
            {
                // includes all 'joined' field names
                var fieldName = fld.Name; // fld.AliasName
            }
            foreach (var fld in anyRow.GetFields().Where(fld => fld.FieldType != FieldType.Geometry))
            {
                // get all field values
                var fieldValue = (anyRow[fld.Name] == null) ? string.Empty : anyRow[fld.Name].ToString();
            }
        }
    }
}
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
OSINT_ENGINEER
New Contributor III

Finally we solved the issue. We implemented a kind of wrapper before accessing the underlying RowCursor and this custom implementation did not handled the GetTableDefinition exception correctly when the layer or standalone table is having a join. Sometimes it is really helpful by just letting someone know which things are not related to the problem.

Thank you so much for narrowing this down.

0 Kudos
ThiPham12
New Contributor III

Hi Wolf, 

Would your query sample above also work for querying geodatabase tables? If not, how would you modify it? Thanks!

 

0 Kudos