title: SQL Table to CSV using LINQ
body: <p>I'm trying to get a table into a comma delimited CSV file. I am currently achieving it like this:</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>This creates a csv fine. But my question is, is there a more streamlined way I could achieve this <strong>without</strong> individually specifying each column? In some cases, I'd like to do a <strong>select all</strong>, but with the tables having lots of columns, it seems a bit clunky. </p>