I'm trying to get a table into a comma delimited CSV file. I am currently achieving it like this:
var csv = new StringBuilder("id,Name,Address,City,State\n");
var delimiter = ",";
var newline = "\n";
using (var db = MyDatabase())
{
var query = from c in db.Customers select c;
foreach(var q in query)
csv.Append(q.id).Append(delimiter)
.Append(q.name).Append(delimiter)
.Append(q.address).Append(delimiter)
.Append(q.city).Append(delimiter)
.Append(q.state).Append(newline);
}
This creates a csv fine. But my question is, is there a more streamlined way I could achieve this without individually specifying each column? In some cases, I'd like to do a select all, but with the tables having lots of columns, it seems a bit clunky.