簡體   English   中英

在ASP.NET MVC 3(實體框架)中渴望加載

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

我有一個簡單的數據結構

  • 雇員
  • 員工有清單
  • 大學設有教育系
  • 系和大學的名稱為字符串(我指的是系和大學也是實體)

我的問題是,如何在實體框架中快速加載特定的雇員的教育列表以及每種教育的大學和部門信息。

在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);

但是我的include只接受字符串參數( 使用System.Linq

我怎么解決這個問題?

謝謝...

不是在System.Linq中,而是在System.Data.Entity中(因此使用System.Data.Entity),並且存在於EF 4.1中,但是我必須承認我不知道它出現在哪個版本中。

該代碼段適用於EF I Thin的新版本。 您正在使用哪個4.x版本?

您應該能夠使用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