I have a class in linq that query db table like this, and the question is: How do I export that data to csv? I have tried link suggested and I am using linq2csv and still w
LINQtoCSV doesn't preserve your column order unless you use the [CsvColumn(FieldIndex = 1)] attribute on all your properties. But who wants to do that? I would use ServiceStack.Text library. It preserves column orders by default. Works like this:
string csv = ServiceStack.Text.CsvSerializer.SerializeToCsv<>(exportData);