Text file contains order and order detail lines. First line in order header. After that there is variable number of detail lines. After detail there is blank line followed by next order etc. For order line first field is order number. For detail line first field is 1 always.
128502 02.01.2012 20120 02.01.2012
1 Wine 0 1300
1 Meat 5,8333 5,83
128503 02.01.2012 20123 02.01.2012
1 Wine 20 130
1 Meat 1,33 283,23
1 Cow 2,333 333,23
....
This file need to be readed into list of entities:
class Order {
public string Number; // order number from first field, primary key
public string Date;
... other fields
}
class OrderDetails {
public string Number; // order number from previous line , foreign key to Order
public string ProductName;
... other fields
}
(Instead on Number custom integer id column can also used for relation)
How to read such file in C# ASP.NET MVC2 using FileHelpers library or other way ?
Update
sample
http://www.filehelpers.com/example_multirecords.html
referenced from
Multiple CSV strutures with FileHelpers
shows how to read two tables. How to create relation between those tables: During reading foreign key to order column should added to details table. How to implement this, getting last order number from previous order line and annd it to detail record ?