Viewing entries in
Development

Comment

LINQ to SQL with WCF - Lazy Loading and Caveats

Just a quick tip for those of you working with LINQ and WCF.

LINQ-to-SQL natively supports lazy loading as long as your entities are still managed by the DataContext. However, when you pass your entities across WCF your entities become detached from the DataContext so you can’t lazy load on the client side - which makes perfect sense.

The question is how do you then pass a LINQ entity and its child collections across WCF?

This is where the DataLoadOptions class comes in handy. This class allows you to specify exactly what child collections to load along with your entity.

Without this you would have to make two service calls - one to get the parent object and another to get the child collection.

Comment

Comment

The Aggregate method in LINQ

One little known and scarcely document feature of LINQ is its Aggregate method. This function is very useful when you want to do something to the whole collection.

Lets say I have the follwoing BlogEntry class

public class BlogEntry  
{ 
    public Tags { get; set; } 
}

Now what do I do if I want to build a tag cloud?

Comment