Eager Loading

Posted by Andrew on June 06, 2007

Alex has been thinking a bit about object eager-loading (prefetch) retrieval strategies recently.

The LINQ to SQL approach of using a Lambda is interesting and was the approach we used on BackgroundMotion:

Contribution contribution = Repository<Contribution>
      .Find(1)
      .Including(c => c.ContributionTags);

What’s more interesting to me however is that now we have a way to refer to symbols in a type safe way. Useful for things like data binding etc. where we want to specify a property and where currently we have to use a string. That’s not to say that this Lambda syntax is optimal for this but what can you do? :-)

With respect to eager load strategies our new domain model/persistence framework LightSpeed has the notion of a “named aggregate” - aggregate being a term taken from Domain-driven design. Basically we use an attribute called EagerLoad at the association level in the model:

[EagerLoad(AggregateName="ContributionDetail")]
public readonly EntityCollection<ContributionTag> _contributionTags
  = new EntityCollection<ContributionTag>();

Then we can specify an aggregate name as part of our query.

Query query = new Query(Entity.Attribute("Title").Like("A%"));
query.AggregateName = "ContributionDetail";
IList<Contribution> contributions = Repository.Find<Contribution>(query);

The key point is that we are being explicit about naming the aggregates.

Trackbacks

Use this link to trackback from your own site.

Comments

Leave a response

  1. Mindscape - MindBlog Tue, 26 Jun 2007 03:10:02 CDT

    [...] LightSpeed, this is of course done using the EagerLoad [...]

  2. [...] In the posts leading up to the challenge, I speculated about how some kind of new DSL might be needed to express the information that would be needed for the mapper to be able to solve the challenge. This exact information is contained in the LightSpeed concept of a “named aggregate”. [...]

  3. Colin JackNo Gravatar Wed, 27 Jun 2007 08:59:36 CDT

    I haven’t paid much attention to Lightspeed but I like the idea of aggregates influencing the ORM aspects. I must say that normally I don’t like putting persistence related attributes in the domain but in this case I think it works very nicely.

  4. AndrewNo Gravatar Wed, 27 Jun 2007 17:09:39 CDT

    Hi Colin,

    Thanks. Persistence Ignorance is a trade-off and LightSpeed takes a reasonably pragmatic approach.

    Cheers,

    Andrew.

Comments