Definition Query Problem

Discussion created by rohit.irpenwar on Jan 3, 2012
Latest reply on Jan 6, 2012 by rohit.irpenwar
I am facing a problem with selection of feature from a layer in ArcGis Desktop 9.3.1. Here are the details of problem.
1. I have two Equipment layers Layer1 and Layer2. Both represent same feature class "Equipment" and also have same class ID. The difference in them is that, both have different definition query. Layer1 feature layer has Definition query "Category is Copper Equipments" while layer2 has "Category is Fiber Equipment". So both these layers are mutually exclusive.
2. When I select copper equipment using the ArcGis Tool, the selection is appropriately reflected. I can see the equipment selected only in layer1.
3. Now I open tool.
a. This tool stores selection data before tool is invoked.
b. performs operation needed, manipulates selection as and when needed.
c. Copies back the selection data stored in step a to reflect original selection set.
4. The problem is in step 3.c. What I am trying to do here is all I am going through each feature in original selection set and select it in particular layer. Here is the code to do that:

int classID = feature.Class.ObjectClassID;
var layerFeatureClass = featureLayer.FeatureClass;
if (null != layerFeatureClass && layerFeatureClass.FeatureClassID == classID)
var queryFilter = new QueryFilterClass()
{ WhereClause = "OBJECTID = " + feature.OID };
var cursor = layerFeatureClass.Search(queryFilter, true);
IFeature toBeSelected;
while ((toBeSelected = cursor.NextFeature()) != null)
map.SelectFeature(featureLayer, toBeSelected);
The problem is "if (null != layerFeatureClass && layerFeatureClass.FeatureClassID == classID)" is satisfied by both layer1 and layer2 and same feature is selected in both layers when there is only one feature.

I am looking for some solution to solve this problem.
1. To select a feature in just one layer (layer1) and not both.
2. If there is any way that I can assign my original selection set directly to Map FeatureSelection, instead of iterating through each layer and each feature.

Any code snippet or suggestion will be helpful. Thanks in advance.