I am getting an output from a DataTable for certain columns that have been defined in a string array: string[] columnsToBeUnique;
var ordered = dataTable1
.AsEnumerable()
.Select(column => columnsToBeUnique.Select(name => column[name]))
.Order()
.ToArray()
;
Without the .Order() I am getting the desired output.
The the output however is not ordered so I want to order the output. When I add the .Order(), an error Failed to compare two elements in the array. is thrown.
I also tried:
var ordered = dataTable1
.AsEnumerable()
.Select(column => columnsToBeUnique.Select(name => column[name]))
.OrderBy(x=>x)
.ToList();
What am I doing wrong?
AsEnumerable(), the item in theSelect()call is a row, not a column. Additionally, you should probably also skip theToList()/ToArray()call, and just keep the result as an Enumerable until you really need the array or list.