>>So is there a reason you didn't create a new table an manually loop through the rows? You are trying to force LINQ to do something it wasn't designed to do (create a new DataTable with a different structure). If you need the results as a DataTable, it needs to have a structure defined so that DataRows can be created for it. If you don't want to do that, you could write a method that would convert an IEnumberable< object> to a DataTable. Or you could create a class to hold the results of your query and use that instead of a DataTable to pass the results to the other function.
>
>I thought I can use LINQ to do this transformation in memory without a need to loop through the rows. But looks like I would need to do it manually as suggested by Bill originally.
>
>Unless I will try to incorporate most of the code from our conversion methods here.
>
>The only reason I need a datatable is because our method to convert to our XML string accepts datatable. Since it loops through every row, it means I would need double looping. I'd rather try to figure out if I can somehow create something similar to use and do that loop directly myself.
You do realize that the LINQ query would also be looping through the rows, right? The only thing you could do without looping would be to add DataColumns with expressions (
http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx), but that wouldn't handle the proper or replicate functions without some very messy code.