score:1

Accepted answer

Your concern about size of the query and size of the result set are tangible.

As @BrokenGlass mentioned EF doesn't allow you doing filtering or ordering on includes. If you want to order or filter relations you must use projection either to anonymous type or custom (non mapped) type:

        var query = db.Leagues
                      .Where(l => l.URLPart.Equals(leagueName))
                      .Select(l => new 
                          {
                              League = l,
                              Events = l.LeagueEvents.Where(...)
                                                     .OrderBy(...)
                                                     .Take(3)
                                                     .Select(e => e.Event)
                              ... 
                          });

score:0

Unfortunately EF doesn't allow to selectively load related entities using its navigation properties, it will always load all Foos if you specify Include("Foo").

You will have to do a join on each of the related entities using your Where() clauses as filters where they apply.


Related Articles