views:

9

answers:

1

Hi folks

Im new to MVC, EF4 and Linq, so forgive my ignorance

If im using a Linq Query to return data to pop into a viewmodel, I can include tables with a relation and get to the data without relying on lazy loading.

However I have a problem eager loading data that isnt in a directly relatede table. e.g I have fixtures that relate to a season which in turn relates to a competition type. When querying the fixtures table with an include for season I can pass the list of fixtures into my viewmodel and can see the season being populated in the object:

var fixtures = (from f in predictorDB.Fixtures.Include("Season")
                  select f).ToList();

However, I have no idea how to pass along the competitionType as I need the title from it. If I look at the Season in a particluar fixture, the corresponding competitionType is null (but populated when lazy loading is on)

Thanks

+2  A: 

Did you try something like this?

var fixtures = (from f in predictorDB.Fixtures.Include("Season.Competition") 
                  select f).ToList(); 
Ladislav Mrnka
it all looks so simple now :) thanks
dmce