简体   繁体   English

在ASP.NET MVC 3(实体框架)中渴望加载

[英]Eager loading in ASP.NET MVC 3 (Entity Framework)

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: 在ASP.NET MVC教程中,存在类似以下的查询:

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 ) 但是我的include只接受字符串参数( 使用System.Linq

How can I solve this problem? 我怎么解决这个问题?

Thank you... 谢谢...

不是在System.Linq中,而是在System.Data.Entity中(因此使用System.Data.Entity),并且存在于EF 4.1中,但是我必须承认我不知道它出现在哪个版本中。

That snippet is for a new version of EF I thin. 该代码段适用于EF I Thin的新版本。 What 4.x version are you using? 您正在使用哪个4.x版本?

You should be able to use the name(s) of the Navigation properties: 您应该能够使用Navigation属性的名称:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM