This question is locked. New answers and comments are not allowed.
I am pretty new to Linq and Telerik ORM so please be gentle.
I have a database with the following tables: Customers, Invoices and InvoiceItems.
Using Linq (vb.net) I can get a list of customers doing the following:
I can then loop through all the customers, invoices and items as follows:
The problem I am having is simple. This will result in many calls to the database. When I access customer.Invoices, the ORM tool executes a sql statement to get the invoices and so on.
I'd like to be able to write a vb.net linq query that will return all customer objects and populate the child invoices and invoice line items.
I thought the following line query would do it but it doesn't as when I loop through customer invoices a query is fired again.
How would I do this?
I have a database with the following tables: Customers, Invoices and InvoiceItems.
Using Linq (vb.net) I can get a list of customers doing the following:
dim results = (from c as customer in model.customers select c).ToList
For
each customer as Customer in results
For
each invoice as Invoice in customer.Invoices
For
each item as InvoiceItem in invoice.InvoiceItems
'Do something with the invoice item
Next
Next
Next
I'd like to be able to write a vb.net linq query that will return all customer objects and populate the child invoices and invoice line items.
I thought the following line query would do it but it doesn't as when I loop through customer invoices a query is fired again.
dim result = (from c as customer in model.customers
join i as invoice in model.invoices on i.customerid equals c.customerid
join itm as invoiceitem in model.invoiceitems on itm.invoiceid equals i.invoiceid
order by c.customerid, i.invoiceid, itm.itemid
select c, i, itm).ToList
How would I do this?