I would like to create a functionality that works similar to SqlDataReader.Read()
I'm reading a flat-file from .txt/.csv and returning it as a datatable to my class handling business logic. This iterates through the rows of the datatable, and transforms the data, writing into a structured database. I use this structure for multiple import sources.
Large files though, work really, really slowly. It is taking me 2h to go through 30 MB of data, and I would like to get this down to 30 min. One step in this direction is to not read the entire file into a DataTable, but handle it line by line, and keep memory from getting klogged.
Something like this would be ideal: PSEUDOCODE.
FlatFileReader ffr = new FlatFileReader(); //Set FlatFileParameters
while(ffr.ReadRow(out DataTable parsedFlatFileRow))
{
//...Business Logic for handling the parsedFlatFileRow
}
How can I implement a method that works like .ReadRow(out DataTable parsedFlatFileRow)
?
Is this the right direction?
foreach(obj in ff.lazyreading()){
//Business Logic
}
...
class FlatFileWrapper{
public IEnumerable<obj> lazyreading(){
while(FileReader.ReadLine()){
yield return parsedFileLine;
}
}
}