I'm trying to refactor some slow running code which writes XML using nested loops of several datatables. I read that using linq to write the xml would be faster. I'm not well versed in linq, so I was hoping to get some help here.
Some things I need to mention is that the current architecture uses a webservice which returns data to us in dataTables. We then go through the datatables (iteratively), and there are several which results several nested loops.
example:
dt1 = Webservice.getStuff();
for each (datarow r1 in dt1.Rows) {
dt2 = Webservice.getMoreStuff(r1[col1], r1[col2]);
// write out some xml
for each (datarow r2 in dt2.Rows) {
dt3 = Webservice.getEvenMoreStuff(r2[col1], r2[col2]);
// write out more xml
for each (datarow r3 in dt3.Rows) {
// write out more xml
}
}
}
As you can see for obvious reasons, this is terribly slow. Is there a way to speed this up using linq? What would you guys suggest as a more efficient approach to refactor this? I'm sorry if the details are vague...
I appreciate any help anyone could offer.