views:

35

answers:

3

Hello,

I've been trying to implement a custom ORM for our project and am interested to learn how LINQ to SQL or Entity Framework lazy load objects.

I read some about EntitySet and realized it has a Load() method. Does anyone know how exactly Load works? I'm assuming it should have a reference to DataContext (or ObjectContext in EF) to load the requested object(s).

Mosh

A: 

Exactly. Lazy loading works only if entity is still attached to context. It is usually implemened as proxy on the top of some collection or object so the first time you access the proxy it loads the object or collection.

Ladislav Mrnka
A: 

Here is an article dealing with types of query execution in LINQ to SQL.
As for Entity Framework, here is a similar article.

Devart
A: 

Thanks. But I just realized proxy is used with POCO objects and if you use the designer generated code, no proxy is generated. In this case, I noticed a private (or maybe internal) field pointing to ObjectContext. So, the entity can talk to ObjectContext to query for more data if required.

Mosh