Now let's talk about this line...
if (featureLayer.Name.Contains("ASSEMBLY"))
When you define your utility network schema, you can set the association deletion semantics for a container or structure type. You can see these in the Network Properties dialog that you can get by right-clicking on the utility network layer.
There are three values for this setting:
- None. When you delete the container, the association is automatically deleted. The content features are left behind (no longer part of the container)
- Cascade. When you delete the container, the content features are automatically deleted with it (and the containment associations between them, naturally).
- Restrict. You are unable to delete the container without first deleting the content. This is the scenario you are dealing with above.
Now the reason this setting exists is to prevent users from accidentally deleting a container that contains a large number of features- like a large switching cabinet or even a substation.
I would consider two things.
1. Instead of looking for the name "Assembly", ask the feature if it is a container and, if so, what is the association deletion semantics. You can do this as follows:
bool needToDeleteAssociations = false;
Element element = un.CreateElement(tempFeat);
AssetType assetType = element.AssetType;
if (assetType.AssociationRoleType == AssociationRoleType.Container) {
if (assetType.AssociationDeletionSemantics == AssociationDeleteType.Restricted) {
needToDeleteAssociations = true;
}
}
(Structures can have association deletion semantics too)
2. The second thing to consider is... should you be doing this? The schema was defined to restrict deletion of these containers. Was it intentional? If so, your code is... well... subverting that setting. If it wasn't intentional, maybe the right solution isn't to write any code at all but to change the schema to not have this setting...
I can't answer the question for you, but I would encourage you to ask it if you haven't already.
--Rich