Trouble Selecting from FeatureLayer containing Definition Query

212
7
Jump to solution
04-04-2018 09:11 AM
Highlighted
Occasional Contributor

My Definition Queried featurelayer clearly contains the field# "Material;" however, my Select() returns the exception:  "GeodatabaseFieldException," field does not exist or is unaccessible.

The source FeatureLayer is a Complex Edge from a Geometric Network...(Problem?)

If I first remove the Definition Query from the FeatureLayer, the Select executes properly (Material = CI).

Select Method is supposed to drill through Definition Queries appropriately:

"...If there is a definition query set on the MapMember, the Select() method will automatically work on the subset of rows in the MapMember that meet the definition criteria. You specify an additional query that will be applied after the MapMember's definition query by passing valid QueryFilter object for the QueryFilter parameter.
If the MapMember has any joins, this Select() method takes that into account.

To ensure maximum robustness, callers should explicitly dispose of the returned ArcGIS.Core.Data.Selection in either a using statement or a finally block."

Can someone point me in the right direction?

Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Occasional Contributor

The issue was with my handling of SQL Syntax in the whereclause for the queryfilter.  When a codedvalue data type is String, the value must be enclosed in SINGLE QUOTES.

failed syntax:  WhereValue = Form1.GVar.ms_attfn + Form1.GVar.Oper8tr + Form1.GVar.ms_v;

 proper syntax: WhereValue = Form1.GVar.ms_attfn + Form1.GVar.Oper8tr + "'" + Form1.GVar.ms_v + "'";

View solution in original post

7 Replies
Highlighted
Esri Regular Contributor

Hi Mike,

I set up a similar situation and tried to reproduce your issue.  I have a map in Pro which contains a feature layer that points to a feature class that is a complex edge in a geometric network.  The feature layer has a query definition set up on it (Phase Designation is Equal to 4).

I then wrote an add-in that grabbed that feature layer and executed a Select() and a Search() on that layer.  Both worked fine.

bool DoTest(Layer myLayer)
{
   FeatureLayer featureLayer = myLayer as FeatureLayer;
   string definitionQuery = featureLayer.DefinitionQuery; // to confirm that it is set when stepping through debugger

   // Create a query definition
   QueryFilter queryFilter = new QueryFilter
   {
      WhereClause = "FEEDERID = 'GR-202'"
   };

   int searchCount = 0;
   using (RowCursor cursor = featureLayer.Search(queryFilter))
   {
      while (cursor.MoveNext())
      {
         searchCount++;
      }
   }

   using (Selection selection = featureLayer.Select(queryFilter, SelectionCombinationMethod.New))
   {
      int selectcount = selection.GetCount();
   }
   return true;
}

Could you send me some information about what you are trying to do?  If you are using a QueryFilter, is it possible that you are using the same field that appears in the definition query?  Could the layer definition be hiding the table field that you are trying to use?

Thanks,

--Rich

Reply
0 Kudos
Highlighted
Occasional Contributor

The FeatureLayer represents water mains, Definition Queried by DATASET = ABANDONED.

Here is a sequence of step that lead to the issue:

1. Grab the search layer from the active map

2. Populate a list of field names from it using List<FieldDescription>.  (I am absolutely making available the same field from the Definition Query to the user, which is "DATASET.")

3. User selects which field to search/select. Based on selected field, it is routed to an appropriate whereclause and fieldtype for conversion that sets up the actual feature selection.

4. DATASET = Abandoned is a CodedValueDomain.  Fields with CodedValueDomains are sent to an IList<string> of codedvaluepairs.values, which are then selectable by the user.

5. Finally, a spatialqueryfilter is applied to a FeatureLayer Select().

If I do not SetDefinitionQuery(""); select() returns the exception:  "geodatabasefieldexception," field does not exist or is inaccessible.  *I get this exception when trying to select out of any fieldtype (string, integer, CodedValueDomain, etc.).  *Seems none of the table fields are accessible through the Definition Query.

If I grab the DefinitionQuery before setting it to nothing, and re-instate it after the selection, the features are selected without the original DefinitionQuery, but show VISUALLY as you'd expect with the DefinitionQuery intact. (cheating).  Not what I need.

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Could you send me a short code snippet showing me how you are building the WhereClause and other properties of the QueryFilter that you are passing into FeatureLayer.Select()?

Thanks.

Reply
0 Kudos
Highlighted
Occasional Contributor

.cs provided (not necessarily short...)  Thanks.

Reply
0 Kudos
Highlighted
Esri Regular Contributor

Mike,

I've looked through your code and haven't found anything obviously wrong.

My understanding from our conversation above is that if this line is present the code works, and if it is commented out the call to FeatureLayer.Select() throws an exception:

srch_lyr3.SetDefinitionQuery("");    

Is this true?  If so, that would seem to be a bug, but I cannot reproduce it to be sure.  It's not a generic problem with the API, but could be some combination of your database and map.  At this point, your best approach is to submit this to technical support.  They'll probably want a data sample and a smaller code sample that demonstrates the problem. I'll contact our liaison with technical support to let them know they can work with me on this issue.

Sorry I cannot help more.

--Rich

Reply
0 Kudos
Highlighted
Occasional Contributor

Thanks, Rich.

Yes, you are correct.  Exception if "srch_lyr3.SetDefinitionQuery("");" not in place.

I'll attempt to reproduce on a smaller scale, and submit as possible bug to technical support.

Reply
0 Kudos
Highlighted
Occasional Contributor

The issue was with my handling of SQL Syntax in the whereclause for the queryfilter.  When a codedvalue data type is String, the value must be enclosed in SINGLE QUOTES.

failed syntax:  WhereValue = Form1.GVar.ms_attfn + Form1.GVar.Oper8tr + Form1.GVar.ms_v;

 proper syntax: WhereValue = Form1.GVar.ms_attfn + Form1.GVar.Oper8tr + "'" + Form1.GVar.ms_v + "'";

View solution in original post