C
cpp.mbs
Hi all,
I have two tables in a database: invoices and invoiceItems.
I need to fetch them from a database and create a collection of
invoice entities, each of them associated whith its corresponding
invoice items.
This is what I am doing now:
1. Fech the invoices in a list.
2. Fech the invoiceItems in another list.
3. Loop through the invoice items list and for each item do a inner
loop to search the corresponding invoice and add the item to the
invoice.
To optimize a little I fetch the invoice items sorted by invoiceId
from the database and then in the invoiceItems loop, store always the
last invoice and if the current invoiceItem has the same invoiceId
than the previous, then assign it directly to the last invoice.
But I wonder if there is a more efficient way.
Would it be better to store all the invoices in a dictionary and then
loop through the items and get directly the invoice by its id key from
the dictionary or would be this method a waist of memmory?
thanks!
I have two tables in a database: invoices and invoiceItems.
I need to fetch them from a database and create a collection of
invoice entities, each of them associated whith its corresponding
invoice items.
This is what I am doing now:
1. Fech the invoices in a list.
2. Fech the invoiceItems in another list.
3. Loop through the invoice items list and for each item do a inner
loop to search the corresponding invoice and add the item to the
invoice.
To optimize a little I fetch the invoice items sorted by invoiceId
from the database and then in the invoiceItems loop, store always the
last invoice and if the current invoiceItem has the same invoiceId
than the previous, then assign it directly to the last invoice.
But I wonder if there is a more efficient way.
Would it be better to store all the invoices in a dictionary and then
loop through the items and get directly the invoice by its id key from
the dictionary or would be this method a waist of memmory?
thanks!