Syndicate

News

My name's Marco De Sanctis and I'm an IT professional from Italy. This is my technical blog, about .NET and related application development and design technologies.

Download my Resume (.doc)

Recent Comments

6/26/2008 at 12:21 AM

I really hope you could help me out on this. Say I...
by Roy

Read more...

6/14/2008 at 4:14 PM

Yep, it happened to me too. It violates the princi...
by Gian Maria

Read more...

6/13/2008 at 5:32 AM

Thank you very much, your postinge.on the coattail...
by cindex

Read more...

6/12/2008 at 1:06 PM

Okay. Maybe sometime I'll try to make my own, inhe...
by Lyr

Read more...

6/11/2008 at 4:09 PM

Hello Lyr,ImageSourceConverter is a TypeConverter ...
by Marco De Sanctis

Read more...

Recent Posts

Unleash the power of VisualStateManager with custom states

6/30/2008 at 12:12 AM

Read more...

Blend 2.5 June CTP and custom controls templating

6/25/2008 at 10:18 AM

Read more...

TransactionScope timeout

6/14/2008 at 12:01 AM

Read more...

Custom controls and default template in Silverlight 2 Beta 2

6/11/2008 at 11:37 AM

Read more...

Silverlight 2 Beta 2 Documentation Available

6/6/2008 at 10:17 AM

Read more...

When Lazy Loading associations is useful

posted on Thursday, May 22, 2008 12:28 PM | Filed Under [ LINQ Software Architecture ]

I was going to reply to a feedback to my last post, but from how much I was writing I realized it could deserve a post on its own.

When we decide to adopt the Domain Model pattern to represent data, we're going to deal with complex object graphs: it means that instead of SomeRelatedEntityId properties, we will have concrete references to related entities, a property of SomeRelatedEntity type in this case

Obviously, when you start a business transaction and you know from the beginning that the property X will be accessed, it could be (not always, read below!) a wise choice to eager fetch it to avoid too many DB round trips. However, I consider LazyLoad very useful in at least two practical cases:

  • n-level Master-Details: for example, a form with a header to edit the master entity, a grid below for its details and a button for each row which opens an AJAX modal popup to edit the detail's details. Without LazyLoad you should execute a huge query on the beginning (or many smaller ones) to fetch everything, and perhaps the user only wants to modify a Master's field. Oh... and what if the 2nd level details have many-to-one associations towards other entities? How big should our join be?
  • There are good chances that the related entity is still in the identity map: let's think about a list of entities with many-to-one association towards the same entity, for example a list of bills of the same customer. Without lazy load, you would fetch the same data many times, with lazy load and identity map, you will have no joins, only one query towards the Customers table, then the same entity will be used for every Bill.

Comments

Gravatar
# re: When Lazy Loading associations is useful
Posted by alkampfer on 5/30/2008 9:55 AM
In fact one of the greatest missing of entity framework is lazy loading. With domain model fetch strategies are really important, and the programmer sould have a wide range of choice, and lazy load probably will fits well most of the time.

alk.
Post Comment
Title *
Name *
Email
Url
Comment *  
Please add 4 and 6 and type the answer here: