2

I have a simple data structure

  • Employee
  • Employee has List
  • Education has University, Department
  • Department and University has Name as string (I mean Dept. and Univ. are also entity)

My question is, how can I eagerly load specific Employee's education list and each education's university and department information in Entity Framework.

In ASP.NET MVC tutorials there is a query like:

var viewModel = new InstructorIndexData();
viewModel.Instructors = db.Instructors
    .Include(i => i.OfficeAssignment)
    .Include(i => i.Courses.Select(c => c.Department))
    .OrderBy(i => i.LastName);

But my include takes only string parameter (with using System.Linq)

How can I solve this problem?

Thank you...

2 Answers 2

4

Is't not in System.Linq, but in System.Data.Entity (so using System.Data.Entity) and exists in EF 4.1, but I must admit I don't know in which version it appeared.

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

1 Comment

Thank you! I updated to Entity Framework 4.3. using.System.Data.Entity worked for me.
2

That snippet is for a new version of EF I thin. What 4.x version are you using?

You should be able to use the name(s) of the Navigation properties:

viewModel.Instructors = db.Instructors
    .Include("OfficeAssignment")
    .Include("Courses.Department")   // not so sure about this one
    .OrderBy(i => i.LastName);

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.