Wednesday, October 20, 2010

EF4 whitelist/explicit eager loading

In linq to sql it was very simple:

    var loadOptions = new System.Data.Linq.DataLoadOptions();
    loadOptions.LoadWith<alliance>(a => a.Players);
    dc.LoadOptions = loadOptions;

where dc was the datacontext.

This specifies that any queries that are submitted to this DataContext that return an Alliance object/entity would also go ahead on the same db trip and fetch it's related Players.

In EF4.0 so far it looks like you have to resort to magic strings. Magic strings are a pet peeve of mine. Your compile time type safety goes out the window in this type of magic string use.

Here are 2 solutions I've found on my googling that can get rid of the magic strings for EF4.


No comments:

Post a Comment