LinqToCSV - Writting chunk of files

  • Thread starter Thread starter FcabralJ
  • Start date Start date
F

FcabralJ

Guest
I'm using Csv Helper to write out a Linq Query with million of rows. I would like to split the output by, for instance, 1 million of rows each. Could I do that or should I use other type of writting method?

Here is my code:

var _path = UniversalVariables.outputCsvFiles + "entire_output.csv";

var pvQuery = from car in Cars
select car;


if (!Directory.Exists(UniversalVariables.outputCsvFiles))
{
Directory.CreateDirectory(UniversalVariables.outputCsvFiles);
}

using (
var sw = new StreamWriter(_path))
using (
var csv = new CsvWriter(sw))
{
csv.
Configuration.Delimiter = UniversalVariables.csvDelimiter;
csv.
Configuration.HasHeaderRecord = true;

csv.
WriteHeader<Car>();
csv.
NextRecord();
csv.
WriteRecords(pvQuery);

sw.
Flush();
}


Continue reading...
 
Back
Top