I presently possess a database that contain many linked objects.

Simplified with less objects:

Song => Versions => Info

Now I realize will be able to eager load each one of these objects when utilizing


However, when Among the finest 1 song using its data this makes to load all of the tunes and all sorts of the references.

Can there be an simpler way like :


Or will i need to use:

foreach( Version version in versions)

It's possible for those who have a couple of related objects, however i am getting like 10 objects which have subojects themselves too...

Please show me an easy method.

You simply write this:

var song = (from s in db.Song.Include("Versions.Data").Include("Versions.Info")
           where s.ID == 1 // i.e. some filter here
           select s).First();

If for whatever reason this does not really perform the 'Include' (it could fail should you choose interesting things inside your where clause) take a look Tip out for any workaround: Tip 22 - How to make Include really Include

Hope this can help


You might write it like (in VB)

dim song = db.Song.Include("Versions.Data").Include("Versions.Info").Where(Function(s) s.ID = 1).FirstOrDefault()