Hi all I have a weird optimization question, here is the code I have changed some names for simplicity
CollectionObject mycollobj = new CollectionObject();
List<string> MyProducts = new List<string>();
//get collection of selected customers that were passed in
var chckedValues = form.GetValues("assignChkBx");
foreach(string customer in chckedValues )
{
MyProducts.Clear();
//MyProducts is then set to a data access method in my data access class
MyProducts = DataLayerClass.GetProductsFromCustomer(customer);
foreach(string product in MyProducts)
{
string item1 = DataLayerClass.GetItem1(product);
string item2 = DataLayerClass.GetItem2(product);
mycollobj.loaditems(item1, item2);
}
}
Essentially mycollobj is a black box that is used for some fairly involved analysis (that I have no control over). Is there any better way to run this nested algorithm? Any suggestions are valued and please ask if you need clarification on anything. Thanks!
Yes, this line:
MyProducts = DataLayerClass.GetProductsFromCustomer(customer);is going to slow things down (a database call for every customer), also the nestedDataLayerClass.GetItem1()/GetItem2is making things much worse. Rather send down all thecheckedValuesto the database and return a Lookup with the customer and aTuplecontainingitem1anditem2:In short terms, move the logic to a single database query.