473,224 Members | 1,454 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

Linq question: loading an object graph

Let's say we have your basic Invoices and InvoiceItems table. If we load
this in with LINQ:

var query = from i in db.Invoices
select i;

When I then loop through my invoices, if I wanna access the lineItems for a
particular invoice, LINQ runs another query behind the scenes and goes and
gets them for me. So if I wanted to loop through my invoices and print out
the number of invoices thusly:

foreach(Invoice i in query)
WriteLine(i.someInfo, i.lineItems.count);

This means I have to go to the db each time through the loop. If I have
1000 invoices, I make that many round trips to the db, plus the original
query to get the invoices in the first place.

Similarly, if I used LINQ to just gimme the lineitems and then I wanted to
loop through them and access lineItem.Invoice, that means I have to go to
the db each time through the loop. In other words, any "aggregate" objects
don't get filled by the original LINQ query; LINQ waits until you access
them and goes and gets them in a "just in time" fashion.

Now, this is nice and convenient. It takes hardly any code to write this
stuff, and it gets what it needs when it needs to and you don't have to
concern yourself with it. But, I often work with graphs such as this that
have maybe 1000 parent objects, and each one might have 100 children (and
sometimes those children have children). If I have to loop through one of
my object graphs, it would be TONS of trips to the db and long wait times
for my users.

vIs there any way to tell LINQ to get more stuff initially?
Mar 28 '08 #1
1 2200

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rein Petersen | last post by:
Hi all, I'm toying with reflection to try and build a recursive function that generates treenodes of a treeview that represent any given object's graph (of child objects): public TreeNode...
0
by: Rein Petersen | last post by:
Hi all, I'm toying with reflection to try and build a recursive function that generates treenodes of a treeview that represent any given object's graph (of child objects): public TreeNode...
5
by: wbekker | last post by:
Hi, I'm searching for a good pattern for the following problem: In a large object tree, all object implement a property called IsDirty. That flag is set when a property is modified. If a child...
3
by: STom | last post by:
Ok, if I have a class: Public Class MyXClass Public Property X as Integer ..... End Class In my code if I have two instances of this class: Dim myX1 as new MyXClass
1
by: Lucile | last post by:
Hi to All, I am new to this newsgroup, so please bare with me. Here is the deal: I have the following Object Graph: Icell (Interface) Iline (Interface) Itable (Interface) Classes: Cell:...
0
by: Creativ | last post by:
After reading the article (Jeffrey's) about GC, I wonder how to build a object graph to see what object is still alive and if so which object is referring to them. This is also important in...
4
by: BeSharp | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
2
by: fredd00 | last post by:
Hi, i'm trying to use lazy loading with Linq to sql and related objects seems like you can only call the child object if the context is still open, this is not real lazy loading. here is my...
4
by: CSharper | last post by:
I would like know, will it be possible to run a linq statement generated on the fly by a program? Lets say, I have string like the following string t = "from c in doc.Decentents('Value') select...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.