This is the first post in series regarding LINQ technology and related sub-technologies.
This post will show an example of implementing Lazy load pattern using LINQ to SQL and Visual Studio LINQ Visual Designer.
LINQ To SQL continues to amaze me at the control we have over the lazy loading and pre-fetch of properties and associations.
If we have several columns in the database that are fairly heavy, like binary and NVARCHAR(MAX) columns, duplicating the data in the rows could be very expensive. So how then can we avoid the performance impact associated with heavy columns? Delay load ( lazy load ) them of course.
In the example below, I have specified that the Title column (heavy column) be lazy loaded for testing reasons via the Visual Designer:

Now the Visual Designer changes the Title Field from a basic string field:
private string _Title;
to the following decaration which obviously has lazy loading characteristics that we will talk about later:
private System.Data.Linq.Link<string> _Title;
This means the Title property will be lazy loaded, which means it won't be duplicated above and could really help with performance. Thus, for heavy fields you may want to specify they are always delay loaded. Of course, if we want them to be prefetched, we write the very common code to prefetch Categories and now Title when we need them:
using (BlogDataContext context = new BlogDataContext())
{
DataLoadOptions options = new DataLoadOptions();
options.LoadWith<Blog>(c => c.Categories);
options.LoadWith<Blog>(c => c.Title);
context.LoadOptions = options;
Blog blog = context.Blogs.Single<Blog>(c => c.BlogId == 1);
}
Can be usefull.
Original post can be found here.