I'm writing a ASP.Net search page. The page contains serveral custom controls that make up the search query. The RelationPredicateBucket is ideal for this situation as I can share an instance of this object between all controls. Each control can add it's relation and predicates to it and when the user hits "search" i can use the object to get the data from the database.
However, I encountered a little problem. Some of the search controls on the page need the filter aswell, to get some data. And they need to add some relations/predicates to do so. These relations/predicates are of no interest of other search controls, so I thought to copy the RelationPredicateBucket object to use the RelationPredicateBucket internally.
I couldn't find a copy method for the RelationPredicateBucket, so I tried to copy it manualy like:
IRelationPredicateBucket filter = searchObject.GetFilter();
IRelationPredicateBucket subFilter = new RelationPredicateBucket(filter.PredicateExpression);
subFilter.Relations.AddRange(filter.Relations);
This code threw an exception because the AddRange methode would only accept a ICollection as argument.
So I came up with this:
IRelationPredicateBucket filter = searchObject.GetFilter();
IRelationPredicateBucket subFilter = new RelationPredicateBucket(filter.PredicateExpression);
for (int i = 0; i < filter.Relations.Count; i++) {
subFilter.Relations.Add(filter.Relations[i]);
}
It works, but I was wondering if there is any other (more elegant) appoach to do this.