LINQ to SQL enables developers to specify whether the
properties on entities should be prefetched or delay/lazy-loaded on first
access. You can customize the default pre-fetch/delay-load rules for
entity properties by selecting any entity property or association in the designer,
and then within the property-grid set the "Delay Loaded" property to
true or false.
For a simple example of when I'd want to-do this, consider
the "Category" entity class we modeled above. The categories
table inside "Northwind" has a "Picture" column which
stores a (potentially large) binary image of each category, and I only want to
retrieve the binary image from the database when I'm actually using it (and not
when doing a simply query just to list the category names in a list).
I could configure the Picture property to be delay loaded by
selecting it within the LINQ to SQL designer and by settings its Delay Loaded
value in the property grid:
Note: In addition to configuring the default pre-fetch/delay
load semantics on entities, you can also override them via code when you
perform LINQ queries on the entity class (I'll show how to-do this in the next
blog post in this series).