I need information which should be collected in a recursion.
I have a wpf application with the following recursion:
public static int GetClusterTotalDocumentsCount(ref int count, int clusterID, int lastrunid)
{
List<Cluster> subclusters = DBHandler.GetSubClustersOperational(clusterID);
if (subclusters.Count == 0)
return count;
foreach (Cluster subclutser in subclusters)
{
int temp = DBHandler.GetClusterDocumentsCount(subclutser.ID, 0);
count += temp;
GetClusterTotalDocumentsCount(ref count, subclutser.ID, 0);
}
return count;
}
Now I want the same to be done in silverlight. instead of using ADO.net I’m consuming a WCF service for the data. Problem is, the calls are now Asynchronous so I cannot use this recursion. Any ideas?
Think about your solution – you want recursive remote operation? It means separate roundtrip to the server for each cluster in hierarchy! What about creating service operation which will simply return total and recursion will still take a place on server side inside that operation?
Edit:
Btw. doing database queries in recursion (and in sequence) is also wrong approach. SQL server 2005 and newer supports recursive queries natively so you should check them and wrap your call in single stored procedure using CTE (common table expressions) to do recursive query in single roundtrip to the database.