Gets a value indicating whether the ServiceLayer supports queries.

Namespace:  ESRI.ArcGISExplorer.Mapping

Assembly:  ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)

Syntax

C#
public bool CanQuery { get; }
Visual Basic (Declaration)
Public ReadOnly Property CanQuery As Boolean

Field Value

trueTruetruetrue (True in Visual Basic) if this ServiceLayer instance can be queried; otherwise, falseFalsefalsefalse (False in Visual Basic).

Remarks

Queries are executed against an individual child layer of a ServiceLayer, represented by the ServiceChildLayer class. The CanQuery property of the ServiceLayer class enables you to quickly determine whether any of the ServiceChildLayers can be queried. A ServiceLayer can contain one or more ServiceChildLayers which will not all necessarily support queries. It is therefore necessary to also check the CanQuery property on any ServiceChildLayer you wish to query.

If CanQuery is false any queries attempted against the constituent ServiceChildLayers will result in an ExplorerException.

Version Information: This member is supported from version 2.0.0.1500.

Examples

The code below demonstrates the process of connecting to a ServiceLayer and confirming that both the top level ServiceLayer and a specific ServiceChildLayer will support queries before then accessing the Columns, QueryFeatureLimit, and QueryFeatureCount members to ensure a valid query is executed against the ServiceChildLayer via the Query method. Finally, the example connects to the FeatureLayer datasource and gets the number of rows in the result FeatureLayer table.
CopyC#
{

  //Create a new ServiceConnectionProperties instance and populate with connection information
  ServiceConnectionProperties serviceConnProps = new ServiceConnectionProperties(ServiceType.MapServer,
      new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics"),
      "/ESRI_Census_USA");

  //Create a new ServiceLayer instance passing in the ServiceConnectionProperties 
  ServiceLayer serviceLayer = new ServiceLayer(serviceConnProps);

  //Check the ServiceLayer can Connect
  if (!serviceLayer.Connect())
    return;

  //Check this ServiceLayer supports queries
  if (!serviceLayer.CanQuery)
    return;

  //Get the "states" ServiceChildLayer on which we want to execute a query
  ServiceChildLayer serviceChildLayerStates = serviceLayer.FindByName("states") as ServiceChildLayer;

  //Check this ServiceChildlayer supports queries
  if (!serviceChildLayerStates.CanQuery)
    return;

  //Get the collection of columns for the ServiceChildLayer
  ColumnCollection columns = serviceChildLayerStates.Columns;

  //Create the WHERE clause
  string whereClause = string.Empty;

  //Check each column until the alias matches the intended query field
  foreach (Column column in columns)
  {
    //Use column members to confirm the the AliasName and data type
    if (column.AliasName == "POP2007" & column.Type == ColumnType.Integer)
    {
      //Populate the WHERE clause with matched column name, operator and value
      whereClause = column.Name + " > 10000000";
      break;
    }
  }

  //Check the WHERE clause
  if (whereClause == string.Empty)
    return;

  //Get the maximum number of records returnable from the service
  int queryFeatureLimit = serviceChildLayerStates.QueryFeatureLimit;

  //Get the number of features matching the WHERE clause
  int queryFeatureCount = serviceChildLayerStates.QueryFeatureCount(whereClause);

  //IMPORTANT: Check the feature count is not greater than the feature limit
  if (!(queryFeatureCount <= queryFeatureLimit))
    return;

  //Execute the Query method to get a new FeatureLayer containing the results
  FeatureLayer featureLayer = serviceChildLayerStates.Query(whereClause);

  //The FeatureLayer method must be called to access all FeatureLayer members
  if (!featureLayer.Connect())
    return;

  //Implement code to work with FeatureLayer (in this case get the number of rows)
  int numberOfResultFeatures = featureLayer.Table.GetRows().Count;

}
CopyVB.NET
'Create a new ServiceConnectionProperties instance and populate with connection information
Dim serviceConnProps As New ServiceConnectionProperties( _
ServiceType.MapServer, _
New Uri("http://sampleserver1.arcgisonline.com/ArcGIS/services/Demographics"), _
"/ESRI_Census_USA")

'Create a new ServiceLayer instance passing in the ServiceConnectionProperties 
Dim serviceLayer1 As New ServiceLayer(serviceConnProps)

'Check the ServiceLayer can Connect
If Not serviceLayer1.Connect() Then
  Return
End If

'Check this ServiceLayer supports queries  
If Not serviceLayer1.CanQuery Then
  Return
End If

'Get the "states" ServiceChildLayer on which we want to execute a query  
Dim serviceChildLayerStates As ServiceChildLayer = TryCast(serviceLayer1.FindByName("states"), ServiceChildLayer)

'Check this ServiceChildlayer supports queries  
If Not serviceChildLayerStates.CanQuery Then
  Return
End If

'Get the collection of columns for the ServiceChildLayer  
Dim columns As ColumnCollection = serviceChildLayerStates.Columns

'Create the WHERE clause  
Dim whereClause As String = String.Empty

'Check each column until the alias matches the intended query field  
For Each column As Column In columns

  'Use column members to confirm the the AliasName and data type  
  If column.AliasName = "POP2007" And column.Type = ColumnType.[Integer] Then

    'Populate the WHERE clause with matched column name, operator and value  
    whereClause = column.Name + " > 10000000"
    Exit For

  End If

Next

'Check the WHERE clause  
If whereClause = String.Empty Then
  Return
End If

'Get the maximum number of records returnable from the service  
Dim queryFeatureLimit As Integer = serviceChildLayerStates.QueryFeatureLimit

'Get the number of features matching the WHERE clause  
Dim queryFeatureCount As Integer = serviceChildLayerStates.QueryFeatureCount(whereClause)

'IMPORTANT: Check the feature count is not greater than the feature limit  
If Not (queryFeatureCount <= queryFeatureLimit) Then
  Return
End If

'Execute the Query method to get a new FeatureLayer containing the results  
Dim featureLayer As FeatureLayer = serviceChildLayerStates.Query(whereClause)

'The FeatureLayer method must be called to access all FeatureLayer members  
If Not featureLayer.Connect() Then
  Return
End If

'Implement code to work with FeatureLayer (in this case get the number of rows)  
Dim numberOfResultFeatures As Integer = featureLayer.Table.GetRows().Count

See Also