Hello
I am looking to split a List into groups of 100, grouped by Customernumber,
The below method has syntax errors. I don't want one Customer information split up in two different groups. Should be included in the same split group.
private List<List<InvoiceLines>> Split(List<InvoiceLines> invoiceLines) { List<List<InvoiceLines>> MySplitInvoices = invoiceLines.GroupBy(row => row.CustomerAccount).Select(c => new { Id = c.Key, list = c.ToList() }) .Select((x, i) => new List<InvoiceLines> { Index = i, Value = x }) .GroupBy(x => x.Index / 100) .Select(x => x.Select(v => v.Value).ToList()) .ToList(); return test; }
Below code Just works fine, except my list contains, customer Information. I don't want one Customer information split up in two different groups. Should be included in the same split group.
private List<List<InvoiceLines>> Split(List<InvoiceLines> invoiceLines) { List<List<InvoiceLines>> SplitInvoices = invoiceLines .Select((x, i) => new { Index = i, Value = x }) .GroupBy(x => x.Index / 100) .Select(x => x.Select(v => v.Value).ToList()) .ToList(); return test; }
Thank you