Eager Loading an indirectly related table
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开发者_StackOverflow社区 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
Did you try something like this?
var fixtures = (from f in predictorDB.Fixtures.Include("Season.Competition")
select f).ToList();
精彩评论