Wooley's LINQ Wonderings

Insights and observations regarding LINQ

DataLoadOptions replaces DataShape

As I continue updating my projects to Visual Studio 2008 Beta 2, I found yet another namespace change. This time, it's not the namespace, but object name that has changed.

With Beta 1, we could specify what objects would be loaded automatically with their parents using the DataShape object that you attach to the DataContext. Here is a bit of code that would load a set of books whenever the associated subject was loaded. This would have the benefit of not lazy loading each child collection and reduces the number of requests between the application and database. Here is the code we used with Beta 1:

            DataShape shape = new DataShape();
            shape.LoadWith<Subject>(subject => subject.Books);
            dataContext.Shape = shape;

With Beta 2, the shape is changed to DataLoadOptions. Thus the above code can be easily re-written as follows:

            DataLoadOptions options = new DataLoadOptions();
            options.LoadWith<Subject>(Subject => Subject.Books);
            dataContext.LoadOptions = options;

Matt Warren discusses the change a bit in the following Linq Forum thread: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1678307&SiteID=1. Personally, I prefer the new name as it disambiguates it from the MSDataShape used with data cubes.

On a related note, if you haven't checked out Matt's blog, it is a definate must read for anyone interested in LINQ to SQL.

Crossposted from http://devauthority.com/blogs/jwooley/default.aspx
Published Wednesday, August 01, 2007 12:48 AM by jwooley

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

James said:

Good. Thanks for your helpful info.

February 20, 2008 12:53 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit