I am in the process of generating XML from a CSV file.
In the picture I attach the result I am waiting for
using (var reader = new StreamReader(csvPath + csvName))
{
using (var csv = new CsvReader(reader))
{
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.RegisterClassMap<MapClass>();
var records = csv.GetRecords<Data>().ToList();
from w in records
select
// group by invoice number ?
new XElement("INVOICE",
new XAttribute("DATE",w._invoiceDate ),
new XAttribute("NUMBER", w._invoiceNumber),
new XAttribute("QTY", w._orderQty)
}
}
I want to display the data grouped by the invoice number with the amounts added up (equivalent to a pivot table). Can I ask you for a tip for me?
using (var reader = new StreamReader(csvPath + csvName))
{
using (var csv = new CsvReader(reader))
{
csv.Configuration.HasHeaderRecord = true;
csv.Configuration.RegisterClassMap<MapClass>();
List<Data> records = csv.GetRecords<Data>().ToList();
var result = records.
GroupBy(x => x._invoiceNumber).
Select(x => new
{
// IGrouping does't contain 'Value" definition
InvoiceNumber = x.Key,
InvoiceQty = x.Value.Sum(y => y._orderQty),
InvoiceTotal = x.Value.Sum(y => y._invoiceTotal)
}).ToList();
}
}