1

The following query fails to load the tables when I execute it:

IEnumerable<Bookmark> tempBookmarks = ListBookmarksByUserID(userID);
IEnumerable<CandidateWithBookmarks> results = (from c in _internshipEntities.CandidateSet
                                            .Include("education")
                                            .Include("progress")
                                            .Include("contacts")
                                            .Include("availability")
                                            .Include("hosttypes")
                                            .Include("hostsizes")
                                            .Include("hostcapacities")
                                            .Include("hoststates")
                                            .Include("users")
                       join b in tempBookmarks on c.ID equals b.candidates.ID
                       select new CandidateWithBookmarks()
                                  {CandidateObject = c, BookmarkObject = b});
return results;

I have found some articles related to the problem, namely Alex James' article "How to make Include really Include". The solution comes with one caveat:

For this to work your final select must be entities, i.e. select post rather than select new {…}

Which is obviously an issue for the above block of code. Are there any other known work-arounds for this issue that won't break eager loading?

2
  • 1
    Entity Framework doesn't have the concept of forced eager loading. You can request eager loading, but you can't force it. You can work around it, but if someone else later changes the code, you are likely back at square one, so make sure you are checking the IsLoaded property! Commented Sep 18, 2009 at 8:01
  • Thanks for the tip, that helps significantly. Commented Sep 18, 2009 at 14:04

1 Answer 1

2

I think I solved this but it might only work for this specific instance, by moving the includes after the join, the query appears to work:

IEnumerable<CandidateWithBookmarks> results = (
    from b in tempBookmarks
    join c in _internshipEntities.CandidateSet
                                 .Include("education")
                                 .Include("progress")
                                 .Include("contacts")
                                 .Include("availability")
                                 .Include("hosttypes")
                                 .Include("hostsizes")
                                 .Include("hostcapacities")
                                 .Include("hoststates")
                                 .Include("users")
    on b.candidates.ID equals c.ID
    select new CandidateWithBookmarks(){CandidateObject = c, BookmarkObject = b});

Edit: Another query I have similar to this requires an outer join as well, which creates some issues since it then matters what you join to what, unlike this example, but it's still doable.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.