I'm getting a pipe-delimited flat file feed from a service provider that contains invoice, line item, and allocation information all merged into one. However, my object model for handling this information is normalized.
I have a (simplified) object model as follows:
public class Invoice
{
public int InvoiceId {get; set;}
public decimal Amount {get; set;}
public virtual ICollection<LineItem> LineItems {get; set;}
}
public class LineItem
{
public virtual Invoice Invoice {get; set}
public int SequenceNumber {get; set;}
public decimal Quantity {get; set;}
public decimal PricePerUnit {get; set;}
public virtual ICollection<Allocation> Allocations {get; set;}
}
public class Allocation
{
public virtual LineItem LineItem {get; set;}
public string Account {get; set;}
public decimal Distribution {get; set;}
}
My feed file resembles this:
InvoiceId|Amount|LineItemSequenceNumber|Quantity|PricePerUnit|Account|Distribution
1|100.00|1|1.0|50.00|1234567890|25.00
1|100.00|1|1.0|50.00|1111111111|25.00
1|100.00|2|50.0|1.00|1234567890|50.00
2|50.00|1|1.0|50.00|1234567890|50.00
In this example, Invoice
1 has two LineItem
s and LineItem
1 has 2 Allocation
s.
I have loaded the feed file into a variable records
as IList<string[]>
, split at the pipes.
How can I build this as a graph in a single Linq statement? It seems like it should be relatively straightforward but I get lost at the second level when I lose the reference to the pertinent records
variable.